Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins groovy pipeline - calling build step for another pipeline

edit:

according to Andrew Bayer you're not supposed to inject declarative pipelines in to others. Support might come for it in the future but not might not come at all.


I'm currently trying to start a pipeline within a pipeline but I'm wondering what I need to do to make it work. The documentation on the jenkins webpage says that if the new job or pipeline is in the same folder as the first one you can call it from either direct name or absolute path. I've tried all different ways, currently I'm trying absolute path to a file I just checked exists one second earlier but it says that it doesn't exist.

I wonder what the correct way to link different pipelines together are.

steps {
    echo "hello ${env.WORKSPACE}"
    sh "ls ${env.WORKSPACE}"
    sh "ls ${env.WORKSPACE}/jenkins"
    build(job: "${env.WORKSPACE}/jenkins/css-core-pipeline", parameters: [[$class: 'StringParameterValue', name: 'param1', value: "$pass1" ]])
  }

[Pipeline] echo

hello /home/jenkins/workspace/hellopipeline

[Pipeline] sh

[hellopipeline] Running shell script

.+ ls /home/jenkins/workspace/hellopipeline

README.md

.

.

.

jenkins

[Pipeline] sh

[hellopipeline] Running shell script

.+ ls /home/jenkins/workspace/hellopipeline/jenkins

css-ce-pipeline

css-core-pipeline

css-dev-pipeline

css-prod-pipeline

manual.md

.

.

.

ERROR: No item named /home/jenkins/workspace/hellopipeline/jenkins/css-core-pipeline found

Finished: FAILURE

like image 328
Jesper Olsson Avatar asked Jun 22 '17 13:06

Jesper Olsson


2 Answers

The jobname without any prefix should be enough.

build(job: "css-core-pipeline", parameters: [[$class: 'StringParameterValue', name: 'param1', value: "$pass1" ]])

You can use the snippet generator to get a valid step snippet, if this doesn't work. Open the pipeline configuration -> Pipeline Syntax -> Snippet Generator -> Select build step -> Fill fields (there will be an autocomplete for the job name)

like image 88
Philip Avatar answered Oct 08 '22 06:10

Philip


What worked for me was that I was not scaping slashes properly, so I had to replace jobname/feature/my-branch-name like so:

        stage('Calls another pipeline') {
            steps {
                build job: 'jobname/feature%2Fmy-branch-name', parameters: [
                    string(name: 'MY_VAR', value: 'my_value')
                ],  propagate: true, wait: true

            }
        }
like image 30
Simon Ernesto Cardenas Zarate Avatar answered Oct 08 '22 06:10

Simon Ernesto Cardenas Zarate