Lower Jenkins (e.g. v1.x) but requires later Jenkins (e.g. v2.x) functionality (e.g. using git plugin which has some transitive dependencies which requires v2.x).
For some reason , we just wanted a Jenkins server to delegate a task to another Jenkins server.
You've created a script (i.e. python, ruby, groovy, etc) that will trigger a Jenkins task via HTTP protocol. This is not part of this document but the Backend Jenkins Server section is applicable.
Backend Jenkins Server
This is the server that will perform the task.
Setting-up a role that can do remote build
- Click Jenkins -> Manage Jenkins -> Manage and Assign Roles entry and select Manage Roles.
- In the Global roles, add a new role (e.g. remote_triggers) that is allowed to trigger a task remotely.
- Once added enable the following:
Example 1: Sample role configuration
If we have remote_triggers as the new role, we have the following:
Assigning a role to a user
- Click Jenkins -> Manage Jenkins -> Manage and Assign Roles entry and select Assign Role.
- In the Global roles, add a known Jenkins user.
- Once added assign the role.
Example 2: Assign a role following Example 1.
If the known user is GwDevOpsDev, we have the following:
Setting-up the Build Triggers
- On the Build Triggers section, select the Trigger builds remotely (e.g., from scripts).
- Provide an Authentication Token.
Note: You can use https://www.guidgenerator.com/ just remove the hyphen for this.
This will enable you to trigger the job remotely via HTTP Post using one of the following:
Without Build Parameters
With Build Parameters
Example 3: Address to call a task remotely.
If we have the following:
JENKINS_URL = http://d-51306g2.fmg.net:9080
ITEM_NAME=Statement Date Update to Saturday
The URL to call this job remotely with build parameters must be:
User Facing Jenkins Server
This is the Jenkins server that is normally use by the user to invoke tasks but the task is actually being done by a another Jenkins server.
Setting-up Credential to be used with the HTTP request.
- Click Jenkins -> Credentials entry.
- Click the global store seen as follows:
- Click Add Credentials.
- Set the Kind field to Username with Password.
- Set the Scope field to Global if not yet set.
- Set the Username field to the user that can to remote triggering configured on the backend Jenkins server (e.g. GwDevOpsDev from Example 2).
- Set the Password field to a valid password.
- Set the ID field to something unique.
Note: You can use https://www.guidgenerator.com/ for this.
- Click the OK button.
Setting-up a New Item to Delegate Task to Backend Jenkins Server
- Click New Item.
- Provide an Item name.
- Select Freestyle project.
- Click the OK button.
- Click Add build step-> HTTP Request entry.
- Fill-in the URL with the one configured in the backend Jenkins server (e.g. http://d-51306g2.fmg.net:9080/job/Statement%20Date%20Update%20to%20Saturday/buildWithParameters?token=49dcf6a2164147b1871de70b40afef6f from Example 3)
- Select POST for the HTTP mode.
- Click the Advanced… button.
- In the Authenticate field select the set up from Setting-up Credential to be used with the HTTP request section earlier.
- Click the Save button.
- Now every time you click Build now it will complete immediately since the actual build will be done on the Backend Jenkins Server.