我有一个通过声明式管道脚本配置的Jenkins作业。
当构建通过/失败时,我想对相关的Jira问题添加评论。
可用的插件在将其与管道一起使用方面并没有提供很好的文档。我已尝试使用“Jira插件”,因为此答案中对此进行了说明:
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)
有没有人通过管道成功完成此操作?
最佳答案
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/