🔥Let’s Do DevOps: GitHub to Jenkins Custom Integration using Actions, Bash, Curl for API Hacking
This blog series focuses on presenting complex DevOps projects as simple and approachable via plain language and lots of pictures. You can do it!
This past few weeks I’ve skipped all my meetings. I literally got the “hey are you okay” messages in slack. And I’ve been okay! But I’ve found a juicy problem, and I have been hacking on it, and I finally got it working to a sufficient quality and cleanliness that I want to share it in case you also want to!
The problem set is this — Your source code used to be internal to your network, and worked with Jenkins to build and deploy all your code. That integration is a black box, but it works well! However, your source control is moving to ✨The Cloud✨ on GitHub, which is very cool, but presents a series of problems:
- How will GitHub talk to Jenkins in a secure way (Do we put Jenkins on the internet?)
- How will GitHub integrate with Jenkins to run the appropriate jobs and track the outcome?
- How will GitHub authenticate to Jenkins to run jobs?
In the course of solving this problem I’ve learned a ton about Jenkins and even a little about GitHub. Let’s do this.
If you want to skip all the
how we got there and jump right to the
working GitHub Action to track a Jenkins job based on GitHub commit message, scroll to the end of this blog for the GitHub link ❤ :)
Step 0: Grok The Problem
Working with other CI/CD tools, the pipeline always executes within the context of the updated code. There’s no need to propagate a branch name or commit or anything like that, because it’s implicitly known.
However, that’s not how Jenkins works, at least in my environment. Working with dev teams, they described the following workflow:
- A Pull Request (PR) is created with a branch and at least 1 commit.
- This triggers a notice to Jenkins (later on I identified this is a commitNotification API call) that says, “hey Jenkins, ≥1 branches with ≥1 commits have been created in this git repository and need to be built