Skip to content

Commit 5e1a813

Browse files
author
Jared Murrell
committed
updated jira-issue-validator
Updated the docs for the JIRA issue validator pipeline
1 parent a6253b6 commit 5e1a813

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Jira Issue Validator
2+
In order to use this pipeline, you will need the following plugins:
3+
4+
- [Pipeline](https://plugins.jenkins.io/workflow-aggregator): This plugin allows us to store our `Jenkins` _jobs_ as code, and moves away from the common understanding of Jenkins `builds` to an `Agile` and `DevOps` model
5+
- [Pipeline: Declarative](https://plugins.jenkins.io/pipeline-model-definition): Provides the ability to write _declarative pipelines_ and add `Parallel Steps`, `Wait Conditions` and more
6+
- [Pipeline: Basic Steps](https://plugins.jenkins.io/workflow-basic-steps): Provides many of the most commonly used classes and functions used in _Pipelines_
7+
- [Pipeline: Job](https://plugins.jenkins.io/workflow-job): Allows us to define `Triggers` within our _Pipeline_
8+
- [Pipeline: Utility Steps](https://plugins.jenkins.io/pipeline-utility-steps): Provides us with the ability to read config files, zip archives and files on the filesystem
9+
- [GitHub Integration](https://plugins.jenkins.io/github-pullrequest): Provides the ability to customize pull request builds
10+
- [Pipeline: GitHub](https://plugins.jenkins.io/pipeline-github): Allows using GitHub steps within a _Jenkinsfile_
11+
- [GitHub](https://plugins.jenkins.io/github): Provides integration with GitHub
12+
- [JIRA Pipeline Steps](https://plugins.jenkins.io/jira-steps): Allows using JIRA steps within a _Jenkinsfile_
13+
- [JIRA](https://plugins.jenkins.io/jira): Enables integration with JIRA
14+
15+
### Configuring Jenkins
16+
17+
1. Log in to Jenkins and click _Manage Jenkins_
18+
2. Click _Configure System_
19+
3. In the **JIRA Steps** section, provide the required information for connecting to your JIRA server
20+
![jenkins-setup-jira](https://user-images.githubusercontent.com/865381/39254110-587316e2-4877-11e8-93f0-9050a7144ea2.png)
21+
4. In the **GitHub Pull Request Builder** section, fill out the connection information
22+
![jenkins-config-gh-pull-1](https://user-images.githubusercontent.com/865381/39254113-5d8fde58-4877-11e8-81f5-fb037ae06266.png)
23+
![jenkins-setup-gh-pull-2](https://user-images.githubusercontent.com/865381/39254114-5dacc112-4877-11e8-9a0b-f1a8643de7c0.png)
24+
25+
### Creating the Pipeline
26+
1. Log in to Jenkins and click _New Item_
27+
2. Give it a name and select _Pipeline_ as the type
28+
![jira-github-validation](https://user-images.githubusercontent.com/865381/37780888-0e1d3c88-2dc6-11e8-8cd8-4b3efc55a1f1.png)
29+
3. Check the box to enable _GitHub Project_ and provide the URL for the repository
30+
![jenkins-github-pr-validation](https://user-images.githubusercontent.com/865381/37780961-31ee22bc-2dc6-11e8-88a3-9bec66621840.png)
31+
4. Check the box to trigger on _GitHub Pull Requests_
32+
4a. Choose _Hooks with Persisted Data_ as the **Trigger Mode*
33+
4b. Check the box to _Set status before build_
34+
4c. Add _Commit changed_ and _Pull Request Opened_ as the **Trigger Events**
35+
![jenkins-github-integration-pr-trigger](https://user-images.githubusercontent.com/865381/37780979-38469c84-2dc6-11e8-98b2-19c06b77fcf4.png)
36+
37+
38+
### Example Pipeline
39+
This pipeline functions by taking the _issue ID_ from the pull request body, performing a lookup in JIRA, then setting the status of the build in GitHub based on the _transition_ in JIRA.
40+
41+
```groovy
42+
node {
43+
properties([
44+
[$class: 'BuildDiscarderProperty',
45+
strategy: [$class: 'LogRotator',
46+
artifactDaysToKeepStr: '',
47+
artifactNumToKeepStr: '',
48+
daysToKeepStr: '',
49+
numToKeepStr: '5']
50+
]
51+
])
52+
stage('Validate JIRA Issue') {
53+
//echo sh(returnStdout: true, script: 'env')
54+
// Get the issue number from the PR Title
55+
def prTitleJira = sh(
56+
script: "echo \${GITHUB_PR_TITLE}|awk {'print \$1'}",
57+
returnStdout: true)
58+
59+
// Get the issue number from the PR Body
60+
def prBodyJira = sh(
61+
script: "echo \${GITHUB_PR_BODY}|awk {'print \$1'}",
62+
returnStdout: true)
63+
64+
// Convert the discovered issue to a string
65+
def prIssue = prBodyJira.trim()
66+
67+
// Validate that the issue exists in JIRA
68+
def issue = jiraGetIssue (
69+
site: "JIRA",
70+
idOrKey: "${prIssue}")
71+
72+
// Validate the state of the ticket in JIRA
73+
def transitions = jiraGetIssueTransitions (
74+
site: "JIRA",
75+
idOrKey: "${prIssue}")
76+
77+
// Create a variable from the issue state
78+
def statusId = issue.data.fields.status.statusCategory.id.toString()
79+
def statusName = issue.data.fields.status.statusCategory.name.toString()
80+
81+
// Validate that it's in the state that we want
82+
if (statusId == '4') {
83+
setGitHubPullRequestStatus (
84+
context: "",
85+
message: "${prIssue} is in the correct status",
86+
state: "SUCCESS")
87+
} else {
88+
setGitHubPullRequestStatus (
89+
context: "",
90+
message: "${prIssue} is not properly prepared in JIRA. Please place it in the current sprint and begin working on it",
91+
state: "FAILURE")
92+
}
93+
}
94+
}
95+
```
96+
97+
### Visual Status
98+
1. Create a new file with a commit message. The JIRA plugin will automatically comment on the ticket if you use the `JIRA-[number] #comment <comment>` format
99+
![jenkins-jira-commit](https://user-images.githubusercontent.com/865381/37779241-544b8bc8-2dc2-11e8-8dd6-aaca12556ed0.png)
100+
101+
2. Create a new pull request, and be sure that `JIRA-[number]` is the first word in the _body_
102+
![jenkins-jira-pr-body](https://user-images.githubusercontent.com/865381/37779286-7056832c-2dc2-11e8-9cfb-82a931d40ca0.png)
103+
104+
#### Ticket is not _In Progress_
105+
![jenkins-jira-pr-check-fail](https://user-images.githubusercontent.com/865381/37779349-9480bfd8-2dc2-11e8-895a-38088692f071.png)
106+
107+
#### Ticket is _In Progress_
108+
![jenkins-jira-validator-pass](https://user-images.githubusercontent.com/865381/37779337-8f198138-2dc2-11e8-915f-a28130bc02ba.png)

0 commit comments

Comments
 (0)