This tutorial shows how to create a Jenkins pipeline job to upload build and deployment data with HCL Accelerate. It is part of the HCL Accelerate VSM series with Jira and GitHub; however, it can be used as a general reference on its own.
Requirements: Assumes prior completion of HCL Accelerate VSM tutorial series with Jira and GitHub, but not entirely required.
1. Create a Jenkins Integration
Follow the tutorial for “Creating a Jenkins Integration with HCL Accelerate”.
2. Add the Jenkins Integration to the Value Stream
Jenkins integrations are added to value streams in a different way than other integrations. There is no need to edit a vsm.json file; however, we will need to create an “Application” on the value stream’s pipeline in order to have a target for build and deployment data.
2.1 Navigate to “Pipeline” and click “Add app”.
2.2 Select “Jenkins” from the dropdown.
2.3 Type an application name. The workbook uses the name “JKE App1”.
2.4 The new application should appear as a row within the pipeline. This is all we need for now and we can now return to the value stream.
3. Create a Jenkins Job for Build, DEV, and QA
3.1 Create a new Jenkins Pipeline Job.
3.2 Configure the Pipeline Script
After creating the pipeline, navigate to the pipeline script section. Click “Apply” and “Save” after pasting the script and setting variable values.
- Copy and paste script here
- Set variables to correct values
- Click “Apply” and “Save”
3.2.1 Copy and Paste the Script
node { // URL to Github repository https://github.com/<owner>/<repo> def GITHUB_REPO_URL="https://github.com/User1098429748/jke-app-1" // Get ENV ID values for DEV and QA from HCL Accelerate Value Stream "Download attributes from API" json file def VSM_ENV_ID_DEV="09bd6385-6b46-4fd1-a0b2-56cb0f4ecaf9" def VSM_ENV_ID_QA="cf601828-3001-433c-bedd-f4574c5cc5f0" // VSM_APP_NAME must match your HCL Accelerate pipeline application name def VSM_APP_NAME="JKE App1" // Time to wait before next stage (seconds) def SLEEP_TIME=5 // Do not change below this line. def GIT_COMMIT stage ('cloning the repository'){ currentBuild.displayName = "2.1.1.${BUILD_NUMBER}" majorVersion="${BUILD_NUMBER}" def scm = git branch: 'master', url: "${GITHUB_REPO_URL}" GIT_COMMIT = sh(returnStdout: true, script: "git rev-parse HEAD").trim() echo "GIT_COMMIT=${GIT_COMMIT}" } sh 'printenv' stage ("Build") { echo "Building ${VSM_APP_NAME} (Build:${currentBuild.displayName}, GIT_COMMIT:${GIT_COMMIT}, comit2:${env.GIT_COMMIT}, name:${env.GIT_COMMITTER_NAME})" step($class: 'UploadBuild', id: "${currentBuild.displayName}", versionName:"${currentBuild.displayName}", name: "${currentBuild.displayName}", tenantId: "5ade13625558f2c6688d15ce", requestor: 'admin', //Must specify one of "appId", "appExtId", or "appName" appName: "${VSM_APP_NAME}", revision: "${GIT_COMMIT}", status: "${currentBuild.currentResult}".toLowerCase(), startTime: "${currentBuild.startTimeInMillis}", endTime: "${System.currentTimeMillis()}", debug: false, fatal: false, ) } stage ("Deploy to DEV") { sleep "${SLEEP_TIME}" step([$class: 'UploadDeployment', //"versionExtId" can be used in place of "id" and "versionName" id: "${currentBuild.displayName}", versionName: "${currentBuild.displayName}", name: "${currentBuild.displayName}", description: 'UploadBuild Example', tenantId: "5ade13625558f2c6688d15ce", initiator: "admin", //Must specify one of "appId", "appExtId", or "appName" appName: "${VSM_APP_NAME}", environmentName: 'PROD', environmentId: "${VSM_ENV_ID_DEV}", result: "${currentBuild.currentResult}".toLowerCase(), startTime: "${currentBuild.startTimeInMillis}", endTime: "${System.currentTimeMillis()}", type: "Jenkins", debug: false, fatal: false, ]) } stage ("Deploy to QA") { sleep "${SLEEP_TIME}" step([$class: 'UploadDeployment', //"versionExtId" can be used in place of "id" and "versionName" id: "${currentBuild.displayName}", versionName: "${currentBuild.displayName}", name: "${currentBuild.displayName}", description: 'UploadBuild Example', tenantId: "5ade13625558f2c6688d15ce", initiator: "admin", //Must specify one of "appId", "appExtId", or "appName" appName: "${VSM_APP_NAME}", environmentName: 'PROD', environmentId: "${VSM_ENV_ID_QA}", result: "${currentBuild.currentResult}".toLowerCase(), startTime: "${currentBuild.startTimeInMillis}", endTime: "${System.currentTimeMillis()}", type: "Jenkins", debug: false, fatal: false, ]) } }
3.2.2 Edit Variable Values
Script Variables to Edit
Variable Name | Description | Example |
---|---|---|
GITHUB_REPO_URL | The URL to your GitHub repository that you are using for this workbook. | https://github.com/UrbanCodeHCL Accelerate/JKE-App-1 |
HCL ACCELERATE_ENV_ID_DEV | An ID that uniquely identifies your value stream’s DEV environment | cb348f56-29f3-4ade-9c9f-38daedf3b663 |
HCL ACCELERATE_ENV_ID_QA | An ID that uniquely identifies your value stream’s QA environment | 7a115f90-f4e5-4181-9920-78b216bb4afc |
HCL ACCELERATE_APP_NAME | The HCL Accelerate pipeline application name (use “JKE App1” for the workbook, we will create this pipeline application later) | JKE App1 |
SLEEP_TIME (optional) | The time in seconds to wait between stage transitions. The default is 60 seconds and can be edited as desired. | 60 |
Values for ENV IDs and App Name can be found in “Attributes for API”
The pipeline script requires some values from your HCL Accelerate value stream. To get these values, click “Download attributes for API” from the tool icon dropdown in your value stream. Copy and paste environment IDs and application name from this file to the variables in your script.
3.3 Click “Apply” and “Save”
4. Run the Jenkins Job for Build, Dev, and QA
We are now ready to run the Jenkins job and observe stage changes in the HCL Accelerate value stream. At this point, back in our value stream, there should still be a dot in the “Merged” stage. We will run the Jenkins pipeline job we created which includes three steps: build, DEV deployment, and QA deployment. This means that, upon running the job, we should see the dot make three transitions: Merged –> Build –> DEV –> QA.
4.1 Merged -> Build
4.2 Build -> DEV
DEV -> QA
Seeing Triangles?
HCL Accelerate will get all commit data from this build, so other commits may show up aside from the PR we created. These will be shown as triangles. Although this might be a surprise, it makes perfect sense that a build might include commits that we were not aware of. HCL Accelerate is showing us the true state of our value stream, and this sometimes shows us information we were not expecting.
Explanation
If you just followed along, copy and pasted the script, ran the job, and observed the effects – you might be saying “OK, I see the result, but how is this working??” Of course, to answer that we should study the pipeline script in Jenkins. The two most important parts of the script are the ‘UploadBuild’ and ‘UploadDeployment’ steps described below.
- UploadBuild Step: The UploadBuild class is used to upload build data to HCL Accelerate. The revision parameter is important for linking the build to the work item via GitHub data (GIT_COMMIT in this case). The versionName is important for linking forward to deployments. The appName corresponds to the HCL Accelerate pipeline application name.
step($class: 'UploadBuild', id: "${currentBuild.displayName}", versionName:"${currentBuild.displayName}", name: "${currentBuild.displayName}", tenantId: "5ade13625558f2c6688d15ce", requestor: 'admin', //Must specify one of "appId", "appExtId", or "appName" appName: "${VSM_APP_NAME}", revision: "${GIT_COMMIT}", status: "${currentBuild.currentResult}".toLowerCase(), startTime: "${currentBuild.startTimeInMillis}", endTime: "${System.currentTimeMillis()}", debug: false, fatal: false, )
- UploadDeployment Step: The UploadDeployment class is used to upload deployment data to HCL Accelerate. The versionName parameter is critical for linking to build data. The appName corresponds to the HCL Accelerate pipeline application name, while environmentName and environmentId are used to identify the deployment environment.
step([$class: 'UploadDeployment', //"versionExtId" can be used in place of "id" and "versionName" id: "${currentBuild.displayName}", versionName: "${currentBuild.displayName}", name: "${currentBuild.displayName}", description: 'UploadBuild Example', tenantId: "5ade13625558f2c6688d15ce", initiator: "admin", //Must specify one of "appId", "appExtId", or "appName" appName: "${VSM_APP_NAME}", environmentName: 'PROD', environmentId: "${VSM_ENV_ID_DEV}", result: "${currentBuild.currentResult}".toLowerCase(), startTime: "${currentBuild.startTimeInMillis}", endTime: "${System.currentTimeMillis()}", type: "Jenkins", debug: false, fatal: false, ])
Start a Conversation with Us
We’re here to help you find the right solutions and support you in achieving your business goals.