jenkins调用jira参数实现Jenkins JIRA Pipeline Steps

1、获取参数信息

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

显示结果:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第1张图片

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显示信息:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第2张图片

jira中实现效果:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第3张图片

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显示信息:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第4张图片

jira中实现效果:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第5张图片

4、获取issue信息

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

jenkins获取信息:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第6张图片

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显示信息:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第7张图片

jira实现效果:
jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第8张图片

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值,如下图:

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第9张图片

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第10张图片

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

jenkins调用jira参数实现Jenkins JIRA Pipeline Steps_第11张图片

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

 

你可能感兴趣的:(jenkins,jira)