Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

Configuring Jenkins in 5.1.x

Updated on February 4, 2021

If you are using a Run Jenkins step task in your pipeline, configure Jenkins so that it can communicate with the orchestration server.

  1. 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.
      1. Click CreateSecurityAuthentication Profile.
      2. Enter a name, and then click Create and open.
      3. In the User name field, enter Jenkins user ID.
      4. Click Set password, enter the Jenkins password, and then click Submit.
      5. Click the Preemptive authentication check box.
      6. Click Save.
      7. 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.
  2. If you are using Jenkins version 2.17.6 or later and want to use an API token for authentication, do the following steps:
    1. Log in to the Jenkins server.
    2. Click People, click the user who is running the Jenkins job, and then click ConfigureAPI token.
    3. Generate the API token.
    4. Create an authentication profile on the orchestration server by clicking CreateSecurityAuthentication Profile.
    5. In the User name field, enter the Jenkins user ID.
    6. Click Set password, enter the API token that you generated, and then click Submit.
    7. Click the Preemptive authentication check box.
    8. Click Save.
    9. Go to step 4.

      For more information about configuring authentication profiles, see Creating an authentication profile.

  3. If you are using Jenkins version 2.17.6 or later and want to use a Crumb Issuer for authentication, do the following steps:
    1. Log in to the Jenkins server.
    2. Click Manage JenkinsManage Plugins and select the check box for the Strict Crumb Issuer plug-in.
    3. Click Manage JenkinsConfigure Global Security.
    4. In the CSRF protection section, in the Crumb Issuer list, select Strict Crumb Issuer.
    5. Click Advanced, and then clear the Check the session ID check box.
    6. Click Save.
    7. Create an authentication profile on the orchestration server by clicking CreateSecurityAuthentication Profile.
    8. In the User name field, enter the Jenkins user ID.
    9. Click Set password, enter the Jenkins password, and then click Submit.
    10. Click the Preemptive authentication check box.
    11. Click Save.
    12. 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.).
  4. Install the Post build task plug-in.
  5. Install the curl and jq commands on the Jenkins server. As mentioned above, these can be replaced with any other scripts as well.
  6. Create a new freestyle project.
  7. On the General tab, select the This project is parameterized check box.
  8. Add the DeploymentID and CallBackURL parameters.
    1. Click Add parameter, and then select String parameter.
    2. In the String field, enter DeploymentID.
    3. Click Add parameter, and then select String parameter.
    4. In the String field, enter CallBackURL.
  9. 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:
    1. 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.
    2. 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.
  10. In the Build Triggers section, select the Trigger builds remotely check box.
  11. In the Authentication Token field, select the token that you want to use when you start Jenkins jobs remotely.
  12. In the Build Environment section, select the Use Secret text(s) or file(s) check box.
  13. In the Bindings section, do the following actions:
    1. Click Add, and then select User name and password (separated).
    2. In the Username Variable field, enter client_id.
    3. In the Password Variable field, enter client_secret.
    4. In the Credentials field, click Specific credentials.
    5. Click Add, and then select Jenkins.
    6. In the Add credentials dialog box, in the Username field, enter the client id configured in the oAuth client credentials on Deployment Manager.
    7. In the Password field, enter the client secret.
    8. Optionally enter a description, and click Save.
  14. Add post-build tasks by doing one of the following actions:
    1. If Jenkins is running on Microsoft Windows, go to step 15.
    2. If Jenkins is running on Linux, go to step 16.
  15. If Jenkins is running on Microsoft Windows, add the following post-build tasks:
    1. Click Add post-build action, and then select Post build task.
    2. 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.
    3. 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%.
    4. Click Add another task.
    5. 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.
    6. 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%
    7. Click Save.
    8. Go to step 17.
  16. 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:
    1. Click Add post-build action, and then select Post build task.
    2. 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.
    3. 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
    4. Click Add another task.
    5. 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.
    6. 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
    7. Click Save.
    8. Go to step 17.
  17. To stop a pipeline deployment if a Jenkins build fails, add a post-build script:
    1. Click Add post-build action, and then select Post build task.
    2. 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.
    3. 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
    4. 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
    5. Click Save.

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us