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.
CodePudding user response:
You could enable the option Trigger builds remotely
to trigger your job through the Jenkins API. Once you check the option, you will get the url you need to call in order to trigger the build
Use the following URL to trigger build remotely: JENKINS_URL/job/BranchDiffTests/build?token=TOKEN_NAME
Detailed instructions can be found here.
Once you have the job properly configured, you can send a GET request with the token as a parameter, and have the job executed remotely. Use Bash, Powershell, or whatever scripting language you use within your pipeline to create an API call to this endpoint, and once the call is made, the job should start running.
CodePudding user response:
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
'''
}