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}"
    }
  }
}

猜你喜欢

转载自blog.csdn.net/alittleyatou/article/details/82148657
今日推荐