lud*_*nus 3 github jenkins jenkins-pipeline multibranch-pipeline
更准确地说,我需要获取触发我的多分支构建的 PR 的标签列表。是否可以?
我知道https://github.com/jenkinsci/pipeline-github-plugin但使用了不兼容的 Jenkins 版本和多分支管道。
经过一番调查,我发现了两种获取 PR 标签列表的方法。
def getLabels() {
def labels
def scmHead = jenkins.scm.api.SCMHead.HeadByItem.findHead(currentBuild.rawBuild.getParent())
def owner = scmHead.getSourceOwner()
def repo = scmHead.getSourceRepo()
def prId = scmHead.getId()
withCredentials([usernamePassword(credentialsId: 'GITHUB_CREDENTIALS_ID', usernameVariable: 'UUU', passwordVariable: 'PPP')]) {
def json = sh(
script: "curl -u ${env.UUU}:${env.PPP} https://api.github.com/repos/${owner}/${repo}/issues/${prId}",
returnStdout: true
)
// requires https://plugins.jenkins.io/pipeline-utility-steps plugin
def prInfo = readJSON(text: json)
labels = prInfo.labels
}
return labels
}
Run Code Online (Sandbox Code Playgroud)
if (env.BRANCH_NAME ==~ /PR-\d+/) {
pullRequest.labels.each{
echo "label: $it"
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2692 次 |
最近记录: |