gpt4 book ai didi

github - 如何使用 Jenkinsfile 设置 github 提交状态而不使用拉取请求构建器

转载 作者:行者123 更新时间:2023-12-03 12:48:28 25 4
gpt4 key购买 nike

我们设置了 Jenkins 2 来构建对 github 的每次推送,并且我们不使用 Pull Request 构建器(尽管作为 pull request 的一部分的提交显然也会被构建)。 GitHub Integration Plugin说它只适用于拉取请求构建器,所以这对我们不起作用。

我也试过 github-notify plugin ,但它似乎不适用于我们的案例(可能是因为 repo 是私有(private)的和/或作为组织的一部分拥有,而不是个人用户)。我试过让它推断设置以及手动指定 credentialsId , account , repo ,当然还有 status争论,都没有运气。

这是我的 Jenkinsfile 的缩写版本:

pipeline {
agent { label "centos7" }

stages {
stage("github => pending") {
steps {
githubNotify status: "PENDING", credentialsId: "my-credentials-id", account: "my-account", repo: "my-repo"
}
}
stage("build") {
...
}
}

post {
success {
githubNotify status: "SUCCESS", credentialsId: "my-credentials-id", account: "my-account", repo: "my-repo"
}
failure {
githubNotify status: "FAILURE", credentialsId: "my-credentials-id", account: "my-account", repo: "my-repo"
}
}
}

当我运行构建时,我得到以下信息:
java.lang.IllegalArgumentException: The suplied credentials are invalid to login
at org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep.getGitHubIfValid(GitHubStatusNotificationStep.java:234)
at org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep.getRepoIfValid(GitHubStatusNotificationStep.java:239)
at org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep.access$100(GitHubStatusNotificationStep.java:75)
at org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep$Execution.run(GitHubStatusNotificationStep.java:344)
at org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep$Execution.run(GitHubStatusNotificationStep.java:326)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
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)

我已经通过 Jenkins(在配置系统区域)和在浏览器中手动测试了凭据——用户名和密码是正确的,并且具有对相关存储库的读/写访问权限。

最佳答案

根据 Jenkins GitHub plugin's own example :

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

...

pipeline {
stages {
...
}
post {
success {
setBuildStatus("Build succeeded", "SUCCESS");
}
failure {
setBuildStatus("Build failed", "FAILURE");
}
}
}

不需要多余的插件。只要您安装并正确配置了 GitHub 插件,您甚至不需要执行上述操作,它应该会自动发生。我们也没有使用 Pull Request 构建器,而是使用 Jenkins Multibranch Pipeline。我们只是在 PR 中使用上面的代码片段来获得额外的状态粒度。

关于github - 如何使用 Jenkinsfile 设置 github 提交状态而不使用拉取请求构建器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43214730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com