如何在 GitHub 上重命名 Jenkins 的拉取请求构建器的“状态检查”显示名称

JP *_*dom 6 github jenkins

我们在GitHub上有一个项目,其中有两个Jenkins Multibranch Pipeline作业 - 一个构建项目,另一个运行测试。这两个管道之间的唯一区别是它们具有不同的JenkinsFiles

\n\n

我有两个我怀疑彼此相关的问题:

\n\n
    \n
  1. 在 GitHub 状态检查部分中,我只看到一项具有以下标题的检查: \n continuous-integration/jenkins/pr-merge \xe2\x80\x94 This commit looks good,\n它引导我进入测试Jenkins 管道。这意味着我们的构建管道没有被 GitHub 接收,尽管它在 Jenkins 上可见。我怀疑这是因为两张支票具有相同的名称(即continuous-integration/jenkins/pr-merge)。
  2. \n
  3. 我无法弄清楚如何重命名每个 Jenkins 作业的状态检查消息(即testbuild)。我已经解决过这个类似的问题,但它的解决方案不适用于我们,因为构建触发器在多分支管道中不可用
  4. \n
\n\n

如果有人知道如何针对Jenkins 多分支管道的每个作业更改此消息,那将非常有帮助。谢谢!

\n\n

编辑(只是更多信息):

\n\n

我们已经在存储库上设置了 GitHub/Jenkins webhook,并且构建确实开始了我们的构建测试作业,只是状态检查/消息没有显示在 GitHub 上(仅用于测试)看起来)。\n这是我们用于构建作业的 JenkinsFile:

\n\n
#!/usr/bin/env groovy \nproperties([[$class: \'BuildConfigProjectProperty\', name: \'\', namespace: \'\', resourceVersion: \'\', uid: \'\'], buildDiscarder(logRotator(artifactDaysToKeepStr: \'\', artifactNumToKeepStr: \'\', daysToKeepStr: \'\', numToKeepStr: \'5\')), [$class: \'ScannerJobProperty\', doNotScan: false]])\nnode {\n    stage(\'Initialize\') {\n        echo \'Initializing...\'\n        def node = tool name: \'node-lts\', type: \'jenkins.plugins.nodejs.tools.NodeJSInstallation\'\n        env.PATH = "${node}/bin:${env.PATH}"\n    }\n\n    stage(\'Checkout\') {\n        echo \'Getting out source code...\'\n        checkout scm\n    }\n\n    stage(\'Install Dependencies\') {\n        echo \'Retrieving tooling versions...\'\n        sh \'node --version\'\n        sh \'npm --version\'\n        sh \'yarn --version\'\n        echo \'Installing node dependencies...\'\n        sh \'yarn install\'\n    }\n\n    stage(\'Build\') {\n        echo \'Running build...\'\n        sh \'npm run build\'\n    }\n\n    stage(\'Build Image and Deploy\') {\n        echo \'Building and deploying image across pods...\'\n        echo "This is the build number: ${env.BUILD_NUMBER}"\n        // sh \'./build-openshift.sh\'\n    }\n\n    stage(\'Upload to s3\') {\n        if(env.BRANCH_NAME == "master"){\n            withAWS(region:\'eu-west-1\',credentials:\'****\') {\n                def identity=awsIdentity();\n                s3Upload(bucket:"****", workingDir:\'build\', includePathPattern:\'**/*\');\n                cfInvalidate(distribution:\'EBAX8TMG6XHCK\', paths:[\'/*\']);\n            }\n        };\n        if(env.BRANCH_NAME == "PRODUCTION"){\n            withAWS(region:\'eu-west-1\',credentials:\'****\') {\n                def identity=awsIdentity();\n                s3Upload(bucket:"****", workingDir:\'build\', includePathPattern:\'**/*\');\n                cfInvalidate(distribution:\'E6JRLLPORMHNH\', paths:[\'/*\']);\n            }\n        };\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n

bir*_*230 3

尝试使用GitHubCommitStatusSetter(有关声明性管道语法,请参阅此答案)。您正在使用脚本化管道语法,因此在您的情况下,它将是这样的(注意:这只是原型,并且肯定必须对其进行更改以匹配您的项目特定情况):

#!/usr/bin/env groovy 
properties([[$class: 'BuildConfigProjectProperty', name: '', namespace: '', resourceVersion: '', uid: ''], buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')), [$class: 'ScannerJobProperty', doNotScan: false]])
node {

    // ...

    stage('Upload to s3') {
        try {
            setBuildStatus(context, "In progress...", "PENDING");

            if(env.BRANCH_NAME == "master"){
                withAWS(region:'eu-west-1',credentials:'****') {
                    def identity=awsIdentity();
                    s3Upload(bucket:"****", workingDir:'build', includePathPattern:'**/*');
                    cfInvalidate(distribution:'EBAX8TMG6XHCK', paths:['/*']);
                }
            };

            // ...

        } catch (Exception e) {
            setBuildStatus(context, "Failure", "FAILURE");
        }
        setBuildStatus(context, "Success", "SUCCESS");
    }
}

void setBuildStatus(context, message, state) {
  step([
      $class: "GitHubCommitStatusSetter",
      contextSource: [$class: "ManuallyEnteredCommitContextSource", context: context],
      reposSource: [$class: "ManuallyEnteredRepositorySource", url: "https://github.com/my-org/my-repo"],
      errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
      statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
  ]);
}
Run Code Online (Sandbox Code Playgroud)

请检查链接和链接以获取更多详细信息。