Jira Integration with Spinnaker
Jira is a de-facto issue tracking and project management tool for a lot of enterprises and start-ups. Posting updates to Jira on the status of CI/CD pipelines increases transparency and helps in auditing. Although Spinnaker can be integrated with various tools in the cloud-native space, it doesn’t have a built-in jira stage yet. However, custom stages can be created for creating issues/tasks, update comments, transition issues in Jira.
API driven architecture of Jira allows us to do various actions on Jira using REST APIs. So, via custom stage of Spinnaker we can invoke necessary API and create/manager issues/tasks on Jira.
Spinnaker allows addition of custom-stages via orca-local.yml under halyard profile settings.
Pre-requisites:
- An API token corresponding to a user needs to created so that it can be used in the stages for authentication/authorization.
- Access to halyard config so that custom stage code can be added under /home/spinnaker/.hal/default/profiles/orca-local.yml
1. Custom stage for creating a Jira issue
This custom stage allows user to add a stage to the Spinnaker pipeline that can create an issue in Jira. While adding this stage to orca-local.yml file, base64 encode email:token string and put it under Authorization section as shown below.
webhook:
preconfigured:
- label: "JIRA: Create Issue"
type: addJiraIss
enabled: true
description: Custom stage that add an Issue in Jira
method: POST
url: https://myjirainstance.atlassian.net/rest/api/3/issue
customHeaders:
## Provide the JIRA credentails below in base64 encoded USER:TOKEN
Authorization: Basic bXllbWFpbC5kb21haW4uY29tOm15SmlyYVRva2VuCg==
Content-Type: application/json
payload: |-
{
"fields": {
"project":
{
"key": "${parameterValues['projectid']}"
},
"summary": "${parameterValues['summary']}",
"issuetype": {
"name": "${parameterValues['issuetype']}"
},
"components": [{"name" : "${parameterValues['components']}"}],
"assignee": {
"accountId": "5ee9de1bdefde70abc6c74f1"
},
"customfield_10104": 10,
"duedate": "2021-07-25"
}
}
parameters:
- label: Project ID ("ENG" or "DOCS")
name: projectid
description: Which JIRA project do you want to create an item in?
type: string
- label: Issue Type ("Improvement", "Task", "New Feature", or "Bug")
name: issuetype
description: issuetype
type: string
- label: Priority ("Low", "Medium", or "High")
name: priority
description: priority
type: string
- label: Components ("10103")
name: components
description: component of the project
- label: Issue Summary
name: summary
description: summary
type: string
- label: Description
name: description
description: description
type: string
2. Custom stage for updating a Jira issue
This custom stage allows user to add a stage to the Spinnaker pipeline that can update an issue in Jira. While adding this stage to orca-local.yml file, base64 encode email:token string and put it under Authorization section as shown below.
webhook:
preconfigured:
- label: "JIRA: Update Issue"
type: updJiraIss
enabled: true
description: Custom stage that updates description/summar of an Issue in Jira
method: PUT
url: https://myjirainstance.atlassian.net/rest/api/3/issue/${parameterValues['issue']}
customHeaders:
## Provide the JIRA credentails below in base64 encoded USER:TOKEN
Authorization: Basic bXllbWFpbC5kb21haW4uY29tOm15SmlyYVRva2VuCg==
Content-Type: application/json
payload: |-
{
"update": {
"summary": [
{
"set": "${parameterValues['summary']}"
}
],
"description": [
{
"set": "${parameterValues['description']}"
}
]
}
}
parameters:
- label: Issue ID
name: issue
description: Issue
type: string
- label: Summary
name: summary
description: summary
type: string
- label: Description
name: description
description: description
3. Custom stage for posting comments to Jira issue
This custom stage allows user to add a stage to the Spinnaker pipeline that can post comments under an issue in Jira. While adding this stage to orca-local.yml file, base64 encode email:token string and put it under Authorization section as shown below.
webhook:
preconfigured:
- label: "JIRA: Comment on Issue"
type: comJiraIss
enabled: true
description: Custom stage that posts a comment in a Jira Issue
method: POST
url: https://myjirainstance.atlassian.net/rest/api/3/issue/${parameterValues['issue']}/comment
customHeaders:
## Provide the JIRA credentails below in base64 encoded USER:TOKEN
Authorization: Basic bXllbWFpbC5kb21haW4uY29tOm15SmlyYVRva2VuCg==
Content-Type: application/json
payload: |-
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "${parameterValues['message']}",
"type": "text"
}
]
}
]
}
}
parameters:
- label: Issue ID
name: issue
description: Issue
type: string
- label: Message
name: message
description: message
type: string
4. Transition the status of Jira issue
This custom stage allows user to add a stage to the Spinnaker pipeline that can transition state of an issue in Jira. While adding this stage to orca-local.yml file, base64 encode email:token string and put it under Authorization section as shown below.
webhook:
preconfigured:
- label: "JIRA: Transition Issue"
type: transJiraIss
enabled: true
description: Custom stage that transitions an Issue in Jira
method: POST
url: https://myjirainstance.atlassian.net/rest/api/3/issue/${parameterValues['issue']}/transitions
customHeaders:
## Provide the JIRA credentails below in base64 encoded USER:TOKEN
Authorization: Basic bXllbWFpbC5kb21haW4uY29tOm15SmlyYVRva2VuCg==
Content-Type: application/json
payload: |-
{
"transition": {
"id": "${parameterValues['targetStageID']}"
}
}
parameters:
- label: Issue ID
name: issue
description: Issue
type: string
- label: Target Stage ID
name: targetStageID
description: Target Stage ID (11 is "To Do", 21 is "In Progress", 31 is "In Review", 41 is "Done", 81 is "Additional Info Needed", 71 is "Approved")
type: string