gpt4 book ai didi

jenkins - 如何从 Jenkins 管道向 Jira 问题添加评论?

转载 作者:行者123 更新时间:2023-12-04 21:06:45 24 4
gpt4 key购买 nike

我有一个通过声明性管道脚本配置的 Jenkins 作业。

当构建通过/失败时,我想对相关的 Jira 问题添加评论。

可用的插件没有提供关于将它们与管道一起使用的非常好的文档。我尝试使用“Jira Plugin”,因为它在这个答案中解释过:

Updating Jira tickets from Jenkins workflow (jenkinsfile)

step([$class: 'hudson.plugins.jira.JiraIssueUpdater', 
issueSelector: [$class: 'hudson.plugins.jira.selector.DefaultIssueSelector'],
scm: [$class: 'GitSCM', branches: [[name: '*/develop']],
userRemoteConfigs: [[url: 'https://github.com/something.git']]]])

但我收到此错误:
java.lang.IllegalArgumentException: Unsupported run type org.jenkinsci.plugins.workflow.job.WorkflowRun
at hudson.plugins.jira.JiraIssueUpdater.perform(JiraIssueUpdater.java:69)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
at hudson.security.ACL.impersonate(ACL.java:260)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

有没有人通过管道成功地做到了这一点?

最佳答案

使用 jira-steps-plugin :

pipeline {
stages {
stage('jira') {
steps {
comment_issues()
}
}
}
}

void comment_issues() {
def issue_pattern = "TEST-\\d+"

// Find all relevant commit ids
currentBuild.changeSets.each {changeSet ->
changeSet.each { commit ->
String msg = commit.getMsg()
msg.findAll(issue_pattern).each {
// Actually post a comment
id -> jiraAddComment idOrKey: id, comment: 'Hi there!'
}
}
}
}

关于jenkins - 如何从 Jenkins 管道向 Jira 问题添加评论?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44001016/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com