3

We have a Jenkins CI job, where we will run a job when a pull request is raised. If that job fails in any case, we should not allow the user to merge the pull request. Is there any way we can do using github actions?

  • What do you mean "using GitHub actions"? You want to migrate the CI job over *instead of* using Jenkins? If you want the build status from Jenkins for e.g. branch protection rules, use https://plugins.jenkins.io/github/. – jonrsharpe Jan 05 '21 at 14:28
  • Yes @jonrsharpe i got it, In my case we can't use github actions. we can use only if we dont have an external CI system. So I have used branch protection rules. Thank you – Ramanichandran Jan 07 '21 at 07:22

1 Answers1

3

You could:

The OP Ramanichandran confirms in the comments it is working:

For each failure stage in jenkins, we call this github api

sh('curl "https://api.github.com/repos/reponame/statuses/$GIT_COMMIT?access_token=xxx" \ 
-H "Content-Type: application/json" \ 
-X POST \ 
-d "{\\\"state\\\": \\\"failure\\\", \\\"target_url\\\": \\\"https://jenkinsurl/job/foldername/job/jobname/$BUILD_NUMBER/console\\\", \\\"description\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\", \\\"context\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\"}"') } –
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks Vonc, I followed the branch protection policy step which you suggested. But it allows us to select only the status check found in the last week of the repository. Suppose if we dont have any failed status check found in the last week, how we can restrict the merging – Ramanichandran Jan 07 '21 at 06:59
  • @Ramanichandran Not sure, since I believe you should be able to set the status through API calls, regardless of its date. Did you find a way to make it work? (since you have accepted my answer since your comment) – VonC Jan 07 '21 at 14:48
  • Yes @Vonc, I have checked and implemented that, it is working properly thanks for your help – Ramanichandran Jan 12 '21 at 14:10
  • @Ramanichandran Great! But *how* did you implement that? Any future user readong this page would want to know that. – VonC Jan 12 '21 at 14:57
  • For each failure stage in jenkins, we call this github api sh('curl "https://api.GitHub.com/repos/reponame/statuses/$GIT_COMMIT?access_token=xxx" \ -H "Content-Type: application/json" \ -X POST \ -d "{\\\"state\\\": \\\"failure\\\", \\\"target_url\\\": \\\"https://jenkinsurl/job/foldername/job/jobname/$BUILD_NUMBER/console\\\", \\\"description\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\", \\\"context\\\": \\\"Jenkins-CI-pre-merge-job-sonarscan-failure\\\"}"') } – Ramanichandran Jan 12 '21 at 15:39
  • @Ramanichandran Thank you for the feedback, very useful indeed. I have edited the answer to include your comment, for more visibility. – VonC Jan 12 '21 at 17:54