Skip to content

Instantly share code, notes, and snippets.

@rsimpson2
Created March 26, 2020 16:03
Show Gist options
  • Save rsimpson2/197de8103ebc50552bebe8690bad4db7 to your computer and use it in GitHub Desktop.
Save rsimpson2/197de8103ebc50552bebe8690bad4db7 to your computer and use it in GitHub Desktop.
Jenkinsfile Not Respecting When Clause
pipeline {
agent any
post {
failure {
updateGitlabCommitStatus name: 'jenkins', state: 'failed'
emailext (
mimeType: 'text/html',
subject: "Jenkins Pipeline Failed: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>Pipeline Failure: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
recipientProviders: [[$class: 'RequesterRecipientProvider']]
)
addGitLabMRComment(comment: 'The Jenkins Pipeline Failed')
}
success {
updateGitlabCommitStatus name: 'jenkins', state: 'success'
emailext (
mimeType: 'text/html',
subject: "Jenkins Pipeline Success: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>Jenkins Pipeline Success: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
recipientProviders: [[$class: 'RequesterRecipientProvider']]
)
addGitLabMRComment(comment: 'The Jenkins Pipeline Passed')
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
skipStagesAfterUnstable()
gitLabConnection('DHSGitLab')
}
triggers {
gitlab(
addVoteOnMergeRequest: true,
addCiMessage: true,
skipWorkInProgressMergeRequest: true,
acceptMergeRequestOnSuccess: false,
triggerOnNoteRequest: true,
noteRegex: 'please retry a build',
triggerOnMergeRequest: true,
secretToken: '8b526d3bf2b2ae1d316a88686b02ca3e',
pendingBuildName: 'jenkins',
branchFilterType: 'RegexBasedFilter',
includeBranchesSpec: '^((?!develop).)*$'
)
}
stages {
stage('Clone from Gitlab') {
steps {
step([$class: 'WsCleanup'])
checkout scm
}
}
stage('Install NPM Packages') {
steps {
updateGitlabCommitStatus name: 'jenkins', state: 'running'
sh label: 'Install and Run NPM',
script: '''
npm install
npm uninstall typescript
npm install typescript@3.4.5
'''
}
}
stage('Publish Common Module') {
steps {
sh label: '',
script: '''
node_modules/.bin/ng build common
cd modules/common/dist/
npm publish --registry http://ven-dev-dhsci1.ventera.com:8081/repository/dhs-stats/ --access=public
'''
}
}
stage('Publish Budget Plan') {
when {
branch pattern: '^([0-9]{5}-)?(?i)budget-plan-.*',
comparator: 'REGEXP'
}
steps {
sh label: '',
script: '''
node_modules/.bin/ng build budget-plan
cd modules/budget-plan/dist/
npm publish --registry http://ven-dev-dhsci1.ventera.com:8081/repository/dhs-stats/ --access=public
'''
}
}
stage('Publish Import Logs') {
when {
branch pattern: '^([0-9]{5}-)?(?i)import-logs-.*',
comparator: 'REGEXP'
}
steps {
sh label: '',
script: '''
node_modules/.bin/ng build import-logs
cd modules/import-logs/dist/
npm publish --registry http://ven-dev-dhsci1.ventera.com:8081/repository/dhs-stats/ --access=public
'''
}
}
}
}
@rsimpson2
Copy link
Author

Line 76 is not being picked up in the pipeline even though the branch has budget-plan in the branch name. The same for line 90 for import-logs. We expect branch names to start with a number that is 5 numbers, then followed by the branch name and then anything after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment