如何使用Jenkinsfile不使用拉取请求生成器来设置gith

如何使用Jenkinsfile不使用拉取请求生成器来设置gith

本文介绍了如何使用Jenkinsfile不使用拉取请求生成器来设置github提交状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们让Jenkins 2设置了每次push到github,并且我们不使用Pull Request构建器(虽然提交请求的一部分的提交显然也会被构建)。 说它只适用于拉请求生成器,所以这对我们不起作用。



我也尝试了,但它似乎不适合我们的情况(可能是因为回购是私人和/或拥有属于组织的一部分,而不是个人用户)。我尝试让它推断设置,并手动指定 credentialsId 帐户回购,当然还有 status 参数,所有这些都没有运气。



这是一个缩写版本现在我的Jenkinsfile:

  pipeline {
agent {labelcentos7}

阶段{
阶段(github =>待处理){
steps {
githubNotify status:PENDING,credentialsId:my-credentials-id,account:my -account,repo:my-repo
}
}
阶段(build){
...
}
}

发帖{
成功{
githubNotify状态:SUCCESS,credentialsId:my-credentials-id,帐号:my-account,repo:my-repo
}
失败{
githubNotify状态:FAILURE,credentialsId:my-credentials-id,帐号:my-acco unt,repo:my-repo
}
}
}

当我运行构建时,我得到以下内容:

  java.lang.IllegalArgumentException:所提供的凭据无效登录org.jenkinsci.plugins.pipeline.githubstatusnotification.GitHubStatusNotificationStep.getGitHubIfValid(GitHubStatusNotificationStep.java:234)
在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)
a t org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution $ 1 $ 1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci使用java.util.concurrent.Executors
$ RunnableAdapter.call(Executors.java:511)$ java.util.b
$ java.util.concurrent.Executors $ b $并发.FutureTask.run(FutureTask.java:266)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run( ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

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


后者尚不受支持,并且会生成类似的错误消息:请参阅(仍在第二,如果这些证书在浏览器中工作,但不通过DSL配置文件,则可能是jenkins文件,这可能是由于名称或密码中的特殊字符:看看你是否不必。 p>

We have Jenkins 2 set to build every push to github, and we do not use the Pull Request builder (although commits that are part of a pull request obviously will get built, as well). The GitHub Integration Plugin says that it only works with the pull request builder, so this won't work for us.

I've also tried the github-notify plugin, but it seems not to work for our case (possibly because the repo is private and/or owned as part of an Organizaiton, rather than an individual user). I have tried letting it infer settings as well as manually specifying credentialsId, account, repo, and of course status arguments, all with no luck.

Here's an abbreviated version of my Jenkinsfile at the moment:

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"
        }
    }
}

When I run the build, I get the following:

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)

I've tested the credentials both through Jenkins (in the Configure System area) and manually in a browser -- the username and password are correct, and have read/write access to the repo in question.

解决方案

First, make sure those credentials are global ones, not folder credentials.
The latter is not yet supported and would generate a similar error message: see JENKINS-42955 (still in review)

Second, if those credentials works in a browser but not through a DSL config file lie a jenkinsfile, that might be due to special characters in the name or password: see if you don't have to percent encode reserved characters.

这篇关于如何使用Jenkinsfile不使用拉取请求生成器来设置github提交状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 22:10