How To Update Jira Statuses With Jenkins Pipeline In Cycle Appliance

How To Update Jira Statuses With Jenkins Pipeline In Cycle Appliance

The Cycle Appliance provides a platform that facilitates continuous testing and continuous integration through cloud-based infrastructure running Jenkins in Azure. A key aspect of continuous testing and continuous integration is giving your developers and testers notifications on the status of test and integration builds. This allows teams to stay up-to-date on the progress of tasks and allows faster project cycle time.

For many teams, Jira is a primary source for planning and communication. Jenkins pipelines provide the ability to send updates to Jira upon a completed execution. This article describes an example of configuring Jenkins to send a detailed message to Slack at the end of a Pipeline run.

 

Example Scenario

For the example in this article, we will assume there are tests associated with new functionality that is being developed. Those tests are on a development branch of a code repository.

Upon the first pipeline execution, a test case fails and Jenkins posts an update to the related Jira task specifying the execution failed. After rectifying the issue, a subsequent pipeline execution passes and Jenkins posts an update to Jira confirming the passing tests.

 

Jenkins Pipeline Syntax

We will be using several options available to us in Jenkinsfile syntax to drive our pipeline test execution. Detailed information on Jenksinfile pipeline syntax and usage can be found here.

 

post and always/success/failure

The post section of a pipeline runs at the end of the pipeline’s execution. This is where posting execution results typically happens. Inside the post section, different actions can be taken based on the success of failure status of the test execution. Some actions may need to happen at the end of every execution. Those actions should be placed inside of the always block within the post section.

 

jiraSendBuildInfo

The Atlassian Jira Software Plugin, which is installed with the Cycle Appliance, provides the ability to send an execution status update to a Jira task. 

 

Example Post Syntax

post {
  always {
     jiraSendBuildInfo site: 'YOUR-ORGINIZATION.atlassian.net'
  }
  success {
    script {
       println "All the tests passed."
    }
  }
  failure {
       println "There are some failing tests."
  }
 }

 

In the example above, the post block will run after the completion of preceding stages in the pipeline. The always block will run no matter the result of the pipeline’s execution. If those stages passed, the script in the success block will print out that all the tests passed; however, if the preceding stages failed then the script in the failure block will print out that some tests are failing.

 

Since the jiraSendBuildInfo plugin call is within the always block, every time the pipeline executes, a status update will be sent to the respective Jira issue at the defined site’s Jira.

 

Sending Updates to the Correct Jira Issue

The Atlassian Jira Software Plugin takes care of most everything behind the scenes, leaving very little configuration needed in the pipeline. The one required configuration is the Atlassian url for the respective orginization’s Jira. At the moment, only one site can be set.

 

Once the plugin has determined the correct site to send the update to, it then has two ways to determine what specific Jira issue to update. The recommended way is proper source control branch naming by including the Jira issue’s ID in the branch name. For example, “TYN-1234-Inbnd-Checking” where “TYN-1234” is the respective Jira issue’s ID. The plugin automatically parses out the ID from that branch name and sends the update to that Jira issue. The plugin does give the option of defining the branch parameter, for example “branch: TYN-1234”, when calling the jiraSendBuildInfo; however, the recommended method is having the ID in the branch name being executed, as no changes need to be made to the pipeline in order for the results to be sent to the correct issue.

JiraStatus.png

 

 

    • Related Articles

    • How To Post Jenkins Pipeline Results from the Cycle Appliance to Slack

      The Cycle Appliance provides a platform that facilitates continuous testing and continuous integration through cloud-based infrastructure running Jenkins in Azure. A key aspect of continuous testing and continuous integration is giving your ...
    • How to manage Multi-Branch Pipeline Testing with the Cycle Appliance

      The Cycle Appliance provides a platform that facilitates continuous testing and continuous integration through cloud-based infrastructure running Jenkins in Azure. A key aspect of continuous testing and continuous integration is giving your ...
    • Are There Prerequisites to Deploy the Cycle Appliance?

      The Cycle Appliance provides a platform that facilitates continuous testing and continuous integration through cloud-based infrastructure running Jenkins in Azure. The main objective of the Cycle Appliance is to make getting started with these ...
    • Running Tests with Cycle-CLI Command Line Interface

      Problem Running tests using the full Cycle client is not always practical, especially when combining Cycle Tests with a Continuous Integration or Continuous Testing process. Solution Cycle has the ability to run from the command line using Cycle-CLI. ...
    • Securely Injecting Secrets and Passwords into Cycle

      Handling secrets, like passwords used to login to the the system under test, safely and securely is an important part of maintaining and sharing your tests. Hard-coding passwords in your features in plain text makes them readable to anyone who you ...