我们有一个关于GitHub的项目,它有两个Jenkins多分支管道作业-一个构建项目,另一个运行测试。这两个管道之间唯一的区别是它们有不同的JenkinsFiles。
我怀疑有两个问题是相互关联的:
continuous-integration/jenkins/pr-merge — This commit looks good的检查:continuous-integration/jenkins/pr-merge — This commit looks good,它将我引向测试 Jenkins管道。这意味着我们的build管道不会被GitHub获取,尽管它在Jenkins上是可见的。我怀疑这是因为这两个检查都有相同的名称(即continuous-integration/jenkins/pr-merge)。如果有人知道如何在Jenkins多分支管道的每个作业的基础上更改此消息,那将是非常有帮助的。谢谢!
编辑(只是更多的信息):
我们已经在存储库上设置了GitHub/Jenkins We钩子,并为我们的build和测试作业启动了构建,只是状态检查/消息没有显示在GitHub上(似乎只显示在测试上)。下面是我们的JenkinsFile for build作业:
#!/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:['/*']);
}
};
}
}发布于 2019-01-29 09:41:25
尝试使用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]] ]
]);
}发布于 2020-02-11 10:16:25
您可以使用Github Custom Notification Context SCM Behaviour插件https://plugins.jenkins.io/github-scm-trait-notification-context/
安装之后,转到作业配置。在“分支源”-> " Github“-> "Branch”下单击"Add“,然后从下拉菜单中选择”“。然后,您可以在"Label“字段中键入自定义上下文名称。
发布于 2019-06-04 03:18:02
这个答案很像@biruk1230的答案。但是如果你不想降低你的github插件的级别来解决这个问题,那么你可以直接调用这个API。
void setBuildStatus(String message, String state)
{
env.COMMIT_JOB_NAME = "continuous-integration/jenkins/pr-merge/sanity-test"
withCredentials([string(credentialsId: 'github-token', variable: 'TOKEN')])
{
// 'set -x' for debugging. Don't worry the access token won't be actually logged
// Also, the sh command actually executed is not properly logged, it will be further escaped when written to the log
sh """
set -x
curl \"https://api.github.com/repos/thanhlelgg/brain-and-brawn/statuses/$GIT_COMMIT?access_token=$TOKEN\" \
-H \"Content-Type: application/json\" \
-X POST \
-d \"{\\\"description\\\": \\\"$message\\\", \\\"state\\\": \\\"$state\\\", \
\\\"context\\\": \\\"${env.COMMIT_JOB_NAME}\\\", \\\"target_url\\\": \\\"$BUILD_URL\\\"}\"
"""
}
}这两种方法的问题是,无论如何都会显示continuous-integration/jenkins/pr-merge。
https://stackoverflow.com/questions/54399220
复制相似问题