我有一个通过声明性管道脚本配置的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)
有没有人通过管道成功完成了这项工作?
最佳答案 使用
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!'
}
}
}
}