|
| 1 | +node { |
| 2 | + properties([ |
| 3 | + [$class: 'BuildDiscarderProperty', |
| 4 | + strategy: [$class: 'LogRotator', |
| 5 | + artifactDaysToKeepStr: '', |
| 6 | + artifactNumToKeepStr: '', |
| 7 | + daysToKeepStr: '', |
| 8 | + numToKeepStr: '5'] |
| 9 | + ] |
| 10 | + ]) |
| 11 | + stage('Validate JIRA Issue') { |
| 12 | + //echo sh(returnStdout: true, script: 'env') |
| 13 | + // Get the issue number from the PR Title |
| 14 | + def prTitleJira = sh( |
| 15 | + script: "echo \${GITHUB_PR_TITLE}|awk {'print \$1'}", |
| 16 | + returnStdout: true) |
| 17 | + |
| 18 | + // Get the issue number from the PR Body |
| 19 | + def prBodyJira = sh( |
| 20 | + script: "echo \${GITHUB_PR_BODY}|awk {'print \$1'}", |
| 21 | + returnStdout: true) |
| 22 | + |
| 23 | + // Convert the discovered issue to a string |
| 24 | + def prIssue = prBodyJira.trim() |
| 25 | + |
| 26 | + // Validate that the issue exists in JIRA |
| 27 | + def issue = jiraGetIssue ( |
| 28 | + site: "JIRA", |
| 29 | + idOrKey: "${prIssue}") |
| 30 | + |
| 31 | + // Validate the state of the ticket in JIRA |
| 32 | + def transitions = jiraGetIssueTransitions ( |
| 33 | + site: "JIRA", |
| 34 | + idOrKey: "${prIssue}") |
| 35 | + |
| 36 | + // Create a variable from the issue state |
| 37 | + def statusId = issue.data.fields.status.statusCategory.id.toString() |
| 38 | + def statusName = issue.data.fields.status.statusCategory.name.toString() |
| 39 | + |
| 40 | + // Validate that it's in the state that we want... in this case, 4 = 'In Progress' |
| 41 | + if (statusId == '4') { |
| 42 | + setGitHubPullRequestStatus ( |
| 43 | + context: "", |
| 44 | + message: "${prIssue} is in the correct status", |
| 45 | + state: "SUCCESS") |
| 46 | + } else { |
| 47 | + setGitHubPullRequestStatus ( |
| 48 | + context: "", |
| 49 | + message: "${prIssue} is not properly prepared in JIRA. Please place it in the current sprint and begin working on it", |
| 50 | + state: "FAILURE") |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments