5
votes

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

2
I think what you're looking for is FrankIJ's answer to this question: stackoverflow.com/questions/36306883/…Jacob
The problem is that i'm using a declarative pipeline, you're linking things for groovy pipelinesJesper Olsson

2 Answers

5
votes

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)

1
votes

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

            }
        }