3

I passed params to pipeline B and set the environment variables from parameters. However, "${params.URL}" is evaluated as null.

Pipeline A is declared in Jenkinsfile:

pipeline {
    agent any    

    stages {
        stage('Run on all repos') {

            steps { 
                script {
                    sh 'ls'
                    build job: 'run-on-single-repo'
                    parameters:
                            [string(name:'URL', value:'val')]
}}}}}

Pipeline B is declared in run-on-single-repo.groovy:

pipeline {
    agent any

    stages {

        stage('Find missing dependencies') {

            environment {

                URL = "${params.URL}"

            }

            steps { 
...

Both pipelines are configured in Jenkins as 'Pipeline script from SCM' and work.

How to pass environment variables from pipeline job A to pipeline job B?

1 Answer 1

2

The issue was missing comma between build job and parameters. Below is the correct syntax:

...
                    build job: 'run-on-single-repo',
                    parameters:

... 
1
  • Is run-on-single-repo.groovy the Jenkinsfile equivalent for pipelineB? How do I pass in build job: '<YOUR_PATH_HERE>' command, if it is stored on a relative path?
    – bot
    May 27, 2022 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.