【问题标题】:Updating Jira tickets from Jenkins workflow (jenkinsfile)从 Jenkins 工作流 (jenkinsfile) 更新 Jira 票证
【发布时间】:2016-05-14 18:54:24
【问题描述】:

如何从 Jenkinsfile (jenkins-worflow/pipeline) 中更新 jira 问题? 有没有办法可以使用 Jira Issue Updater plugin 作为 Jenkinsfile 中的一个步骤?

我知道我可以使用 Jira RestAPI,但我想弄清楚我是否可以重复使用 jira-updater-issue 提供的功能。

我正在寻找的是类似于下面调用 Junit 存档器和 atifact 存档器的示例,但调用 jira updater。

    node {
      git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'
      def mvnHome = tool 'M3'
      sh "${mvnHome}/bin/mvn -B -Dmaven.test.failure.ignore verify"
      step([$class: 'ArtifactArchiver', artifacts: '**/target/*.jar', fingerprint: true])
      step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
    }

【问题讨论】:

    标签: jenkins jira jira-plugin jenkins-cli jenkins-workflow


    【解决方案1】:

    Jira Plugin 与 Pipeline 兼容。

    这应该可行:

    step([$class: 'hudson.plugins.jira.JiraIssueUpdater', 
        issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'], 
        scm: [$class: 'GitSCM', branches: [[name: '*/master']], 
            userRemoteConfigs: [[url: 'https://github.com/jglick/simple-maven-project-with-tests.git']]]]) 
    

    您可以在内置的 Pipeline Snippet Generator 中获得完整参考。

    【讨论】:

      【解决方案2】:

      JIRA Steps Pluginupdate an existing Jira Ticket 提供了一种更具声明性的方式:

      node {
        stage('JIRA') {
          # Look at IssueInput class for more information.
          def testIssue = [fields: [ // id or key must present for project.
                                     project: [id: '10000'],
                                     summary: 'New JIRA Created from Jenkins.',
                                     description: 'New JIRA Created from Jenkins.',
                                     customfield_1000: 'customValue',
                                     // id or name must present for issuetype.
                                     issuetype: [id: '3']]]
      
          response = jiraEditIssue idOrKey: 'TEST-01', issue: testIssue
      
          echo response.successful.toString()
          echo response.data.toString()
        }
      }
      

      既然您想使用 Jenkinsfile 来定义您的管道,那应该是您的首选方式...

      【讨论】:

        【解决方案3】:

        因为这对我来说比应该做的要困难得多,所以这里有一个工作示例。这将使用特定值更新工单的自定义字段:

        step([$class: 'IssueFieldUpdateStep',
                issueSelector: [$class: 'hudson.plugins.jira.selector.ExplicitIssueSelector', issueKeys: ticket],
                fieldId: field,
                fieldValue: value
            ])
        

        sn-p 生成器对我不起作用。变量票、字段和值都是字符串。从这里开始,您可以在这里寻找选项:https://www.jenkins.io/doc/pipeline/steps/jira/

        【讨论】:

          【解决方案4】:

          是的,这个页面似乎回答了你的问题:

          https://wiki.jenkins-ci.org/display/JENKINS/Jira+Issue+Updater+Plugin

          安装插件后,添加构建步骤,或构建前/后构建步骤来调用此插件

          在那里,您可以将 REST URL 提供给您的 Jira 服务器、凭据和 JQL 以查找问题

          【讨论】:

          • 您好,谢谢,但我正在寻找使用 jenkins-workflow dsl 的示例。我认为您所指的文档是指使用常规(非工作流程)项目中的 jira-updater,对吗?我的意思是,它告诉你如何使用 jenkins ui。我正在寻找的是从工作流 jenkinsfile 中使用它的方法。
          • 同意。这不是答案。
          猜你喜欢
          • 2014-07-22
          • 1970-01-01
          • 2022-10-15
          • 1970-01-01
          • 2015-08-28
          • 2016-07-12
          • 2019-02-08
          • 2018-03-31
          • 2015-06-27
          相关资源
          最近更新 更多