I'm fairly new to Jenkins. I set up a pipeline in Jenkins for an Angular 7 app. Here is my Jenkinsfile:
pipeline {
agent any
stages {
stage('Checkout') {
steps {
echo 'Checkout master branch'
checkout scm
dir('webapp') {
bat 'npm install'
}
}
}
stage('Build') {
steps {
echo 'Building..'
dir('webapp') {
bat 'npm run ng -- build --prod --baseHref=/webapp/ -optimization=true'
}
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
ftpPublisher paramPublish: null, masterNodeName: '', alwaysPublishFromMaster: true, continueOnError: false, failOnError: true, publishers: [
[configName: 'mattdailey.net', verbose: true, transfers: [
[asciiMode: false, cleanRemote: true, excludes: '', flatten: false, makeEmptyDirs: tur, noDefaultExcludes: false, patternSeparator: '[, ]+',
remoteDirectory: "webapp", removePrefix: "webapp/dist", remoteDirectorySDF: false, sourceFiles: 'webapp/dist/**'
]
], usePromotionTimestamp: false, useWorkspaceInPromotion: false]
]
}
}
}
post {
success {
slackSend(color: '#00FF00', message: "Build Successful")
}
failure {
slackSend(color: '#FF0000', message: "Build Failed")
}
}
}
When I create a build I get the following error:
ng "build" "--prod" "--baseHref=/webapp/" "-optimization=true"
Unknown option: '-n'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
I'm using Jenkins 2.150.3, Angular CLI 7.3.4, NodeJS 10.15.1 in Windows 10. If I take out the '--' between ng and build the command works but it ignores the flags after a build. I think I need to add a path variable for angular cli but I'm not sure where to add it or what the right syntax would be.
@Andrew Lobban Fixing the optimization flag helped. I did have to keep the '--' between ng and build, otherwise it wouldn't recognize any of the flags. When I said it works I meant angular cli would do a regular build without any flags. Thanks.
The same problem I faced with Octopus CICD build. Below solution works for me.
"build": "ng build --prod",
npm run build
Hope it help !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.