kamal
kamal

Reputation: 9785

Can one Jenkins Trigger a job on a remote jenkins

I have 2 Jenkins hosts, and would like First Jenkins to trigger a job on remote Jenkins based on "SUCCESS" in result on the first one. I have looked at various plugins , but they all seem to indicate ONE Jenkins host, where multiple jobs can be chained in this manner.

Upvotes: 12

Views: 35026

Answers (6)

AnthonyW
AnthonyW

Reputation: 1998

Cloudbees supports triggering remote jobs via their Operations Center plugins.

As of operations-center-context version 1.8.0, it is possible to trigger remote jobs from a Pipeline job using the ad-hoc Remote Trigger Job function. The RemoteTriggerJob step will appear in the list of available steps of Pipeline if operations-center-context (v. 1.8.0 +) plugin is installed in the Jenkins Instance.

https://docs.cloudbees.com/docs/cloudbees-ci/latest/pipelines/cluster-triggers#_the_trigger_remote_job_pipeline_step

Example usage in declarative pipeline:

       triggerRemoteJob mode: trackProgressAwaitResult(
            scheduledTimeout: [timeoutStr: '10 minutes'],
            startedTimeout: [timeoutStr: '10 minutes'],
            timeout: [timeoutStr: '40 minutes'],
            whenFailure: stopAsFailure(),
            whenScheduledTimeout: continueAsUnstable(),
            whenStartedTimeout: continueAsUnstable(),
            whenTimeout: continueAsUnstable(),
            whenUnstable: continueAsUnstable()),
            parameterFactories: [
                [$class: 'SimpleString', name: 'MY_STRING_PARAM', value: 'Something-important'],
                [$class: 'SimpleString', name: 'OTHER_STRING_PARAM', value: 'more-important-words']],
            remotePathMissing: continueAsUnstable(),
            remotePathUrl: 'jenkins://jenkins_instance_id/path_to_job'

Note: Parameterized Remote Triggers is a Tier 3: community plugin and is not supported by Cloudbees. https://docs.cloudbees.com/plugins/ci/Parameterized-Remote-Trigger

Upvotes: 0

Yogesh Sagar
Yogesh Sagar

Reputation: 11

Step 1: Install following plugins in both Jenkins.

  1. Generic Webhook Trigger: Job can be triggered from http request.
  2. HTTP Request Plugin: To send http request as build step
  3. Any Build Step Plugin: To use any build step in post-build action.

Step 2: Configure job to be triggered(Jenkins B).

Step 3: In master Jenkins(Jenkins A) configure flexible publish settings in configure system to allow use all build steps as post build actions.

Step 4: In post build actions add another step “Flexible publish”. Using this any build action can be used as post-build action. Add a HTTP Request action. Provide Jenkins B webhook url in url field and save.

Upvotes: 1

johan855
johan855

Reputation: 1626

It's very easy to do using cURL requests, no need for plugins or master>slave relations. It took me 5 minutes from beginning to start. Use the following manual:

https://www.nczonline.net/blog/2015/10/triggering-jenkins-builds-by-url/

Upvotes: 3

tobi42
tobi42

Reputation: 815

Meanwhile, a jenkins plugin became available which makes it a lot easier:

https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Remote+Trigger+Plugin

Upvotes: 10

armandino
armandino

Reputation: 18528

Yes. Configure your Jenkins nodes and label them, say masterand slave (Manage Jenkins -> Manage Nodes).

1) Configure Job A and specify that it can only run on master ("Restrict where this project can be run" and in the label field put master).

2) Configure Job B so that it is only triggered if Job A is successful:

"Post-build Actions" -> "Trigger only if build succeeds"

3) Pin Job B to slave similar to step 1.

Upvotes: -3

Arnestig
Arnestig

Reputation: 2342

You could set up a downstream job on host1 that only builds if first job on host1 succeeds. In this job you would trigger a remote build much like i described it in this answer

Upvotes: 2

Related Questions