Configuring Jenkins in 5.1.x
If you are using a Run Jenkins step task in your pipeline, configure Jenkins so that it can communicate with the orchestration server.
- On the orchestration server, create an authentication profile that uses Jenkins
credentials.
- If you are using a version of Jenkins earlier than 2.17.6, create an
authentication profile on the orchestration server that specifies the
credentials to use.
- Click .
- Enter a name, and then click Create and open.
- In the User name field, enter Jenkins user ID.
- Click Set password, enter the Jenkins password, and then click Submit.
- Click the Preemptive authentication check box.
- Click Save.
- Go to step 4.
For more information about configuring authentication profiles, see Creating an authentication profile.
- If you are using Jenkins 2.17.6 or later and want to use an API token for authentication, go to step 2.
- If you are using Jenkins 2.17.6 or later and want to use a Crumb Issuer for authentication, go to step 3.
- If you are using a version of Jenkins earlier than 2.17.6, create an
authentication profile on the orchestration server that specifies the
credentials to use.
- If you are using Jenkins version 2.17.6 or later and want to use an API token
for authentication, do the following steps:
- Log in to the Jenkins server.
- Click People, click the user who is running the Jenkins job, and then click .
- Generate the API token.
- Create an authentication profile on the orchestration server by clicking .
- In the User name field, enter the Jenkins user ID.
- Click Set password, enter the API token that you generated, and then click Submit.
- Click the Preemptive authentication check box.
- Click Save.
- Go to step 4.
For more information about configuring authentication profiles, see Creating an authentication profile.
- If you are using Jenkins version 2.17.6 or later and want to use a Crumb Issuer
for authentication, do the following steps:
- Log in to the Jenkins server.
- Click and select the check box for the Strict Crumb Issuer plug-in.
- Click .
- In the CSRF protection section, in the Crumb Issuer list, select Strict Crumb Issuer.
- Click Advanced, and then clear the Check the session ID check box.
- Click Save.
- Create an authentication profile on the orchestration server by clicking .
- In the User name field, enter the Jenkins user ID.
- Click Set password, enter the Jenkins password, and then click Submit.
- Click the Preemptive authentication check box.
- Click Save.
- Go to step 4.
For more information about configuring authentication profiles, see Creating an authentication profile.
The following steps describe one of the ways to configure Jenkins jobs for the integration with Deployment Manager to work (using Jenkins Free Style Project as the option). This can be done in multiple different ways (e.g. with workflow plugin and groovy, or scripts in Ant, Gradle, etc.). - Install the Post build task plug-in.
- Install the curl and jq commands on the Jenkins server. As mentioned above, these can be replaced with any other scripts as well.
- Create a new freestyle project.
- On the General tab, select the This project is parameterized check box.
- Add the DeploymentID and CallBackURL parameters.
- Click Add parameter, and then select String parameter.
- In the String field, enter DeploymentID.
- Click Add parameter, and then select String parameter.
- In the String field, enter CallBackURL.
- To add parameters that you can use in Run
Jenkins step tasks in the pipeline, click Add parameter,
select String parameter, and enter the string of the
parameter. The system automatically populates these values in Jenkins tasks. You
can add any of the following strings:
- If you are configuring Jenkins tasks in a merge pipeline, add any of
the following strings:
- DeploymentID: Deployment ID of the pipeline on which the task is triggered.
- DeploymentNumber: Sequence number of the deployment.
- TaskID: TaskID of the Jenkins task.
- CallBackURL: URL to post the status of task.
- OrchestratorURL: URL on which the Jenkins task is configured.
- PipelineName: Pipeline name on which the Jenkins task is configured.
- PipelineID: ID of the pipeline on which the Jenkins task is configured.
- ApplicationName: Application name for which the pipeline is configured.
- ApplicationVersion: Application version for which the pipeline is configured.
- RepositoryName: Repository to publish the merged branch.
- BranchName: Name of the branch for which the merge Jenkins task is configured.
- BranchFilePath: File path to the branch artifact.
- If you are configuring Jenkins tasks in a deployment pipeline, add any
of the following strings:
- DeploymentID: Deployment ID of the pipeline on which the task is triggered.
- DeploymentNumber: Sequence number of the deployment.
- TaskID: TaskID of the Jenkins task.
- CallBackURL: URL to post the status of task.
- OrchestratorURL: URL on which the Jenkins task is configured.
- PipelineName: Pipeline name on which the Jenkins task is configured.
- PipelineID: ID of the pipeline on which the Jenkins task is configured.
- RepositoryName: Repository to publish the merged branch.
- DeploymentArtifactName: Artifact name that the Deploy task uses on the stage on which the Jenkins task is configured.
- ArtifactPath: Full path to the artifact that the Deploy task uses.
- CurrentStage: Name of the stage on which the Jenkins task is configured.
- CurrentStageURL: URL of the system on which the Jenkins task is configured.
- If you are configuring Jenkins tasks in a merge pipeline, add any of
the following strings:
- In the Build Triggers section, select the Trigger builds remotely check box.
- In the Authentication Token field, select the token that you want to use when you start Jenkins jobs remotely.
- In the Build Environment section, select the Use Secret text(s) or file(s) check box.
- In the Bindings section, do the following actions:
- Click Add, and then select User name and password (separated).
- In the Username Variable field, enter client_id.
- In the Password Variable field, enter client_secret.
- In the Credentials field, click Specific credentials.
- Click Add, and then select Jenkins.
- In the Add credentials dialog box, in the Username field, enter the client id configured in the oAuth client credentials on Deployment Manager.
- In the Password field, enter the client secret.
- Optionally enter a description, and click Save.
- Add post-build tasks by doing one of the following actions:
- If Jenkins is running on Microsoft Windows, go to step 15.
- If Jenkins is running on Linux, go to step 16.
- If Jenkins is running on Microsoft Windows, add the following post-build tasks:
- Click Add post-build action, and then select Post build task.
- In the Post-Build Actions section, in the Log text field, enter a unique string for the message that is displayed in the build console output when a build fails, for example BUILD FAILURE.
- In the Script field, enter:
@echo off for /F %%I in ('curl --insecure -d "client_id=%%client_id%%&client_secret=%%client_secret%%&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token ^| jq -r .access_token') do set token=%%~I curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer %token%" -k -X PUT --data "{\"taskStatus\":\"Resolved-Rejected\",\"errors\":[{\"errorMessage\":\"Jenkins job failed. Check here for logs: %BUILD_URL%\"}],\"taskInfo\":{\"outputParameters\":[{\"name\": \"BuildNumber\",\"type\": \"Text\",\"value\": \"%BUILD_NUMBER%\"},{\"name\": \"JenkinsBuildURL\",\"type\": \"Text\",\"value\": \"%BUILD_URL%\"}]}}" %CallBackURL%.
- Click Add another task.
- In the Post-Build Actions section, in the Log text field, enter a unique string for the message that is displayed in the build console output when a build is successful, for example BUILD SUCCESS.
- In the Script field, enter:
@echo off for /F %%I in ('curl --insecure -d "client_id=%%client_id%%&client_secret=%%client_secret%%&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token ^| jq -r .access_token') do set token=%%~I curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer %token%" -k -X PUT --data "{\"taskStatus\":\"Resolved-Completed\",\"taskInfo\":{\"outputParameters\":[{\"name\": \"BuildNumber\",\"type\": \"Text\",\"value\": \"%BUILD_NUMBER%\"},{\"name\": \"JenkinsBuildURL\",\"type\": \"Text\",\"value\": \"%BUILD_URL%\"}]}}" %CallBackURL%
- Click Save.
- Go to step 17.
- If Jenkins is running on Linux, add the following post-build tasks. Use the
dollar sign ($) instead of the percent sign (%) to access the environment
variables:
- Click Add post-build action, and then select Post build task.
- In the Log text field, enter a unique string that for the message that is displayed in the build console output when a build fails, for example BUILD FAILURE.
- In the Script field, enter:
export token=`curl --insecure -d "client_id=${client_id}&client_secret=${client_secret}&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token | jq -r .access_token` curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer ${token}" -k -X PUT --data "{\"taskStatus\":\"Resolved-Rejected\",\"errors\":[{\"errorMessage\":\"Jenkins job failed. Check here for logs: ${BUILD_URL}\"}],\"taskInfo\":{\"outputParameters\":[{\"name\": \"BuildNumber\",\"type\": \"Text\",\"value\": \"${BUILD_NUMBER}\"},{\"name\": \"JenkinsBuildURL\",\"type\": \"Text\",\"value\": \"${BUILD_URL}\"}]}}" $CallBackURL
- Click Add another task.
- In the Log text field, enter a unique string that for the message that is displayed in the build console output when a build is successful, for example BUILD SUCCESS.
- In the Script field, enter:
export token=`curl --insecure -d "client_id=${client_id}&client_secret=${client_secret}&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token | jq -r .access_token` curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer ${token}" -k -X PUT --data "{\"taskStatus\":\"Resolved-Completed\",\"taskInfo\":{\"outputParameters\":[{\"name\": \"BuildNumber\",\"type\": \"Text\",\"value\": \"${BUILD_NUMBER}\"},{\"name\": \"JenkinsBuildURL\",\"type\": \"Text\",\"value\": \"${BUILD_URL}\"}]}}" $CallBackURL
- Click Save.
- Go to step 17.
- To stop a pipeline deployment if a Jenkins build fails, add a post-build
script:
- Click Add post-build action, and then select Post build task.
- In the Log text field, enter a unique string for the message that is displayed in the build console output when a build fails, for example JENKINS BUILD FAILURE.
- In the Script field, enter:
(for Windows) for /F %%I in ('curl --insecure -d "client_id=%%client_id%%&client_secret=%%client_secret%%&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token ^| jq -r .access_token') do set token=%%~I curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer %token%" --data "{\"reasonForAbort\":\"Jenkins task failed\"}" -k -X PUT %OrchestratorURL%/PRRestService/DeploymentManager/v1/deployments/%DeploymentID%/abort
- In the Script field, enter:
(for Linux) export token=`curl --insecure -d "client_id=${client_id}&client_secret=${client_secret}&grant_type=client_credentials" https://10.224.203.11:8443/prweb/PRRestService/oauth2/v1/token | jq -r .access_token` curl --insecure -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization:Bearer ${token}" --data "{\"reasonForAbort\":\"Jenkins task failed\"}" -k -X PUT ${OrchestratorURL}/PRRestService/DeploymentManager/v1/deployments/${DeploymentID}/abort
- Click Save.
Previous topic Configuring the Jenkins project Next topic Adding build steps to import or export the archive