DEV Community

Cover image for Jenkins Pipelines and their dirty secrets 3.

Jenkins Pipelines and their dirty secrets 3.

Richard Lenkovits on August 02, 2017

Tips and Tricks of Pipelines How did this chapter come to be? I was basically just pasting here stuff during work. There are many subtle...
Collapse
 
yooofeng profile image
YangFeng

Hi, Pencillr. Thanks for sharing very useful tips about pipeline in your article. Do you have any idea about getting all names of stage before they have been executed? I mean, how to get all the defined stages' name in the beginning of Jenkinfile?

Collapse
 
pencillr profile image
Richard Lenkovits

Hi, thank you. I don't know of any way that would get you the name of the stages before the stages run, in the Jenkinsfile. Although you could do several things to have the stage names beforehand.
First, you could instantiate a list with the names of the stages at the beginning, and you could reference the elements of it at the stage declaration.

Collapse
 
yooofeng profile image
YangFeng

Thanks for your reply. I think I understand what you mean, a parameters{} block or a input method is feasible.

Collapse
 
forpix profile image
mdali_11 • Edited

Is there a way to check the whether Build A is running or not, If Build A running
Build B should be wait until this Build A has to complete, and then Build B has to complete its build, the pipeline to check the Build A is in Build B.....

Collapse
 
vamsichow profile image
vamsi krishna

Hi Pencillr, Thanks alot for the post. I have one requirement where I have to trigger 2nd stage in pipeline at different time and date after the initial stage. Can you please help me if you have any suggestions?

Collapse
 
bendavidpaz profile image
Benjamin Paz

Did you ever figure out how to trigger 2nd stage in pipeline?

I also have a requirement to trigger just a stage in Jenkinsfile pipeline. This stage should only run daily but all other stages triggered by a code push. Any ideas?

Collapse
 
pavelloz profile image
Paweł Kowalski

Have the same case, no luck so far.

Thread Thread
 
cvega profile image
Casey Vega • Edited

Use what is known as a parameterized pipeline. You can set default environment variables for code runs.

when you want to change the behavior of the pipeline stage you can modify the parameter. If you set the toggle parameter to false in the UI, or by calling the build via URL, it will now skip the first stage because it's not true

Calling via URL:
http://server/job/project/buildWithParameters?toggle=false

pipeline {
  agent any
  parameters {
    booleanParam(name: 'toggle', defaultValue: true)
  }
  stages {
    stage('optional stage') {
      when (toggle: true) {
        sh `make clean`
      }
    }
  }
}
Collapse
 
danis9yearsago profile image
Danis Nya

Hi, Pencillr!
Thanks a lot for your tips, it is really useful. I have two question:

  1. When i execute my stages in parallel, job do not stopped when 1 of 2 stages is fail. How can i fix it?
  2. How can i sorted my logs in parallel execution?

Best regards.

Collapse
 
lewisevans profile image
Lewis Evans • Edited

for #1. you can do

parallel (
    "Unit Test" : {
        build("unit-test-job")
    },
    "Component Test" : {
        build("component-test-job")
    },
    "Build" : {
        build("build-job")
    },
    failFast: true
)

for #2. Not sure you can do that unless you run sequentially

Collapse
 
monika1312 profile image
Monika1312

Hi Pencillr, Thanks for this post.
I have one question.
I understood the use of propagate: false but how to show the stage as fail/red when something is actually failed. My job is failed and shows as green and I don't want to go and click every time inside the stage result.

Collapse
 
bendavidpaz profile image
Benjamin Paz

Hi Pencillr, I would like to trigger just a pipeline stage in Jenkinsfile. This stage should only run daily but all other stages triggered by a code push. Any ideas?

Collapse
 
gusgonnet profile image
Gustavo

Great and very useful tips.
Thank you, Richard!!!