1. 程式人生 > >jenkins呼叫jira引數實現Jenkins JIRA Pipeline Steps

jenkins呼叫jira引數實現Jenkins JIRA Pipeline Steps

1、獲取引數資訊

node {
  stage('JIRA') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      def fields = jiraGetFields idOrKey: 'TES-1'
      echo fields.data.toString()
    }
  }
}

顯示結果:

2、新增單個issue

node {
  stage('JIRA') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      def testIssue = [fields: [ project: [key: 'TES'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'New JIRA Created from Jenkins.',
                                 issuetype: [name: '任務']]]

      response = jiraNewIssue issue: testIssue

      echo response.successful.toString()
      echo response.data.toString()
    }
  }
}

jenkins顯示資訊:

jira中實現效果:

3、新增多個issue

node {
  stage('create issues') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      # Look at IssueInput class for more information.
      def testIssue1 = [fields: [ project: [key: 'TES'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'New JIRA Created from Jenkins.',
                                 issuetype: [name: '任務']]]


      def testIssue2 = [fields: [ project: [key: 'TES'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'New JIRA Created from Jenkins.',
                                 issuetype: [name: '任務']]]

      def testIssues = [issueUpdates: [testIssue1, testIssue2]]

      response = jiraNewIssues issues: testIssues

      echo response.successful.toString()
      echo response.data.toString()
    }
  }
}

jenkins顯示資訊:

jira中實現效果:

4、獲取issue資訊

node {
  stage('get issue') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      def issue = jiraGetIssue idOrKey: 'TES-1'
      echo issue.data.toString()
    }
  }
}

jenkins獲取資訊:

5、更新issue資訊

node {
  stage('edit issue') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      def testIssue = [fields: [ project: [key: 'TES'],
                                 summary: 'New JIRA Created from Jenkins.',
                                 description: 'change',
                                 issuetype: [name: '任務']]]

      response = jiraEditIssue idOrKey: 'TES-02', issue: testIssue

      echo response.successful.toString()
      echo response.data.toString()
    }
  }
}

jenkins顯示資訊:

jira實現效果:

6、通過引數轉換問題

node {
  stage('TransitionIssue') {
    withEnv(['JIRA_SITE=hundsunjira']) {
      def transitionInput =
      [
          transition: [
              id: '31'
          ]
      ]
      jiraTransitionIssue idOrKey:"${params.JIRA_ISSUE_KEY2}" , input: transitionInput
    }
  }
}

其中,JIRA_ISSUE_KEY2是在前面jenkins觸發構建中獲取到的issueID值,如下圖:

7、通過jira觸發,獲取jira各類引數

可獲取引數清單:

https://docs.atlassian.com/jira-rest-java-client-api/2.0.0-m31/jira-rest-java-client-api/apidocs/com/atlassian/jira/rest/client/api/domain/Issue.html#getWorklogs()

例如:獲取關聯的問題id

node {
stage('cat issue') {
withEnv(['JIRA_SITE=wzzjira']) {
    echo 'jira LINK:'
    echo "${params.JIRA_ISSUE_KEY4}"
    }
  }
}