Search code examples
jenkinsbuild

How to invoke a jenkins pipeline A in another jenkins pipeline B in separate Jenkins master?


Important is separate Jenkins master. I expecting something like

script { build job: 'https://second_instance_jenkins.mycompany.com/jobs/alt_build_job', parameters: [] }

However this does not work, I cannot connect to other master server, neither I know how to properly AUTH using this syntax. There are tons of examples how to invoke another job within same Jenkins, but not at separate independent Jenkins master!

Thanks.


Solution

  • Found it. I have to use Parameterized-Remote-Trigger as described here

    https://www.jenkins.io/doc/pipeline/steps/Parameterized-Remote-Trigger/

    I also going to post my working pipeline step. I wish there are more examples in manual.

        steps {
            triggerRemoteJob auth: CredentialsAuth(credentials: '7f89634523-1b42-440d-8053-aa3d523523441d'), 
                enhancedLogging: true, 
                job: 'Build/my-integration', 
                remoteJenkinsUrl: 'https://second_instance_jenkins.mycompany.com/', 
                useCrumbCache: true,
                httpGetReadTimeout: 600,
                httpPostReadTimeout: 600,
                useJobInfoCache: true,
                parameters: '''
                    PROJECT_NAME=core
                    BUILD_TYPE=Debug
                    PLATFORM=Linux
                    '''
            }