我们在 GitHub 上有一个项目,其中有两个 Jenkins Multibranch Pipeline 作业-一个构建该项目,另一个运行测试。这两个管道之间的唯一区别是它们具有不同的 JenkinsFiles 。
我怀疑有两个相互关联的问题:
continuous-integration/jenkins/pr-merge — This commit looks good
,
引导我进入 test Jenkins渠道。这意味着GitHub不会选择我们的 build 管道,即使它在Jenkins上可见。我怀疑这是因为两个支票具有相同的名称(即continuous-integration/jenkins/pr-merge
)。如果有人知道如何针对 Jenkins Multibranch Pipelines 在每个职位上更改此消息,那将非常有帮助。谢谢!
编辑(仅提供更多信息):
我们已经在存储库中设置了GitHub / Jenkins webhooks,并且我们的 build 和 test 作业都已开始构建,只是状态检查/消息没有两者都不会在GitHub上显示(似乎仅用于 test )。 这是我们用于 build 作业的JenkinsFile:
#!/usr/bin/env groovy
properties([[$class: 'BuildConfigProjectProperty', name: '', namespace: '', resourceVersion: '', uid: ''], buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5')), [$class: 'ScannerJobProperty', doNotScan: false]])
node {
stage('Initialize') {
echo 'Initializing...'
def node = tool name: 'node-lts', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
env.PATH = "${node}/bin:${env.PATH}"
}
stage('Checkout') {
echo 'Getting out source code...'
checkout scm
}
stage('Install Dependencies') {
echo 'Retrieving tooling versions...'
sh 'node --version'
sh 'npm --version'
sh 'yarn --version'
echo 'Installing node dependencies...'
sh 'yarn install'
}
stage('Build') {
echo 'Running build...'
sh 'npm run build'
}
stage('Build Image and Deploy') {
echo 'Building and deploying image across pods...'
echo "This is the build number: ${env.BUILD_NUMBER}"
// sh './build-openshift.sh'
}
stage('Upload to s3') {
if(env.BRANCH_NAME == "master"){
withAWS(region:'eu-west-1',credentials:'****') {
def identity=awsIdentity();
s3Upload(bucket:"****", workingDir:'build', includePathPattern:'**/*');
cfInvalidate(distribution:'EBAX8TMG6XHCK', paths:['/*']);
}
};
if(env.BRANCH_NAME == "PRODUCTION"){
withAWS(region:'eu-west-1',credentials:'****') {
def identity=awsIdentity();
s3Upload(bucket:"****", workingDir:'build', includePathPattern:'**/*');
cfInvalidate(distribution:'E6JRLLPORMHNH', paths:['/*']);
}
};
}
}
答案 0 :(得分:1)
尝试使用GitHubCommitStatusSetter
(有关声明性管道语法,请参见this答案)。您正在使用脚本化的管道语法,因此在您的情况下将是这样(请注意:这只是原型,因此必须进行更改以匹配您的特定项目):
#!/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]] ]
]);
}
答案 1 :(得分:0)
这个答案很像@ biruk1230的答案。但是,如果您不想降级github插件来解决该错误,则可以直接调用API。
continuous-integration/jenkins/pr-merge
两种方法的问题在于,无论如何都将显示this.helper.workingExperienceList[0]["start_date"]
。
答案 2 :(得分:0)
您可以使用Github Custom Notification Context SCM Behaviour
插件https://plugins.jenkins.io/github-scm-trait-notification-context/
安装后,转到作业配置。在“分支源”->“ GitHub”->“行为”下,单击“添加”,然后从下拉菜单中选择“自定义Github通知上下文”。然后,您可以在“标签”字段中输入自定义上下文名称。