Jenkins continuous delivery pipeline skip stage based on input
Date : March 29 2020, 07:55 AM
it helps some times Can't you do something like this, it will be blue/green whatever you choose from input, and you can then run the deployment depending on it too? def deployToProduction = true
try{
input 'Deploy to Production'
}catch(e){
deployToProduction = false
}
if(deployToProduction){
println "Deploying to production"
}
|
Jenkins Pipeline conditional stage succeeds but Jenkins shows build as failed
Date : March 29 2020, 07:55 AM
it should still fix some issue So after looking more closely at the log file it helped me to track down the problem. It's worth noting that clicking on the build stage to view the logs is what threw me - this is what I had been doing. When I actually went to the full console log output i saw the error about: Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
def branch = readFile('branch').trim()
if (branch == master) {
...
}
|
Is there a way to skip whole Jenkins Pipeline (not a stage) on conditional
Date : March 29 2020, 07:55 AM
I wish this help you Its been sometime, i solved the issue way back but forgot to post the answer. It may help someone in future. Correct it or add comments for a better solution, i will be happy to use that if found successful. To explain the steps here adding some comments stage('Validation') {
steps {
//Moving in to the directory to execute the commands
dir('servicelayer') {
script {
//Using the git command to check the difference between previous successful commit. ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} is an environment variable comes with GIT Jenkins plugin
//There is a drawback though, if it is the first time you are running this job, this variable is not available and fails the build
//For the first time i had to use ${env.GIT_COMMIT} itself at both places to pass the build. A hack but worth it for future builds.
def strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep servicelayer | wc -l").trim()
if(strCount=="0") {
echo "Skipping build no files updated"
CONTINUE_BUILD = false
} else {
echo "Changes found in the servicelayer module"
}
}
}
}
}
stage('Installation') {
when {
expression { return params.FORCE_BUILD || CONTINUE_BUILD }
}
steps {
dir('servicelayer') {
nodejs(nodeJSInstallationName:"${NODEJS_INSTALLATION_NAME}", configId:"${NODEJS_CONFIG_ID}") {
sh 'npm install --progress=false'
}
}
}
}
|
Jenkins: How to skip a specific stage in a multibranch pipeline?
Date : March 29 2020, 07:55 AM
I wish this help you It sounds like you keep the Jenkinsfile alongside the code, but want to change how the Jenkinsfile runs from an administrative point of view. You could store this stage in a separate (version control flavor of preference) repository. Before you execute the stage, load in the repository then load in the script file and within the stage execute a method defined in that file.
|
Scripted Jenkins pipeline, skip parallel part of stage
Date : March 29 2020, 07:55 AM
around this issue @PatriceM. suggested putting each task into its own stage, which is the best solution I've got at the moment: stage('Stage 1') {
parallel 'Task 1' : {
node('requirements') {
doTask1()
}
}, 'Task 2' : {
stage('Task 2') { // new nested stage that can be marked as skipped by the 'when'
when (mustDoTask2) {
node('requirements') {
doTask2()
}
}
}
}
}
|