DEV Community

Discussion on: Automated Jenkins builds on GitHub pull request

Collapse
 
jeuniiii profile image
Junaid Subhani

Thank you for the article Karolis. Is a great read. I do have one question though. How to make this all work with a Pipeline job ?

With a regular Freestyle Project, it works like a charm. But the checks that I want to run are a part of a pipeline in a Jenkinsfile. So Ive configured HitHub project and build triggers as you mentioned. In the Pipeline section, i put the Refspec and Branch specifier as you mentioned. (See attached image)

Now when I issue a PR, the job Jenkins Job does get triggered but it errors out stating

GitHub pull request #16 of commit bb5673be3bb220c74edec123e4fa58b43f5ccd97, no merge conflicts.
Setting status of bb5673be3bb220c74edec123e4fa58b43f5ccd97 to PENDING with url <MY-JENKINS-URL>/job/pre-commit-test/4/ and message: 'Build started for merge commit.'
Setting status of bb5673be3bb220c74edec123e4fa58b43f5ccd97 to FAILURE with url https://<MY-JENKINS-URL>/job/pre-commit-test/4/ and message: 'Build finished. '
hudson.plugins.git.GitException: Command "git fetch --tags --progress origin +refs/heads/${ghprbActualCommit}:refs/remotes/origin/${ghprbActualCommit} --prune" returned status code 128:
stdout: 
stderr: fatal: Couldn't find remote ref refs/heads/${ghprbActualCommit}

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2099)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1791)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$400(CliGitAPIImpl.java:79)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:472)
    at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:358)
    at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
    at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:113)
    at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:299)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

Any idea why this would happen ?

Collapse
 
krusenas profile image
Karolis

did it fail to use the actual value or you have just changed ref yourself refs/heads/${ghprbActualCommit}? From the past it just seems like you need to find what it really likes to get through that webhook :) Webhook Relay will send whatever github is sending so I guess if you look for similar issues that people face when they have their Jenkins exposed to the public internet, it should be good enough. Haven't tried using pipelines myself :|