Trigger Jenkins pipeline for new tags in Github Repo

Prasanth Kanikicherla
4 min readApr 13, 2020

Recently I wanted to create a Jenkins pipeline which builds only when a developer tags a commit → build it; containerize the artifacts; then push to GKE.

Although it was pretty straight forward to set this up using Jenkins GUI with certain plugins, I particularly wanted to try an approach which satisfies “separation of duties” / automation / portability/ efficiency etc., etc.,.

So, we have the following structure in Github, Project repo, Devops Repo (infra/manifests etc.,) and clusters in GKE.

Requirements:

  1. Trigger build only when a new tag is created.
  2. Separate Jenkinsfile (pipeline) from the project repo in order to allow developers to concentrate only on development and also for reusability.
  3. My personal favourite, keep all pipelines in one place for portability. Hint: Job DSL.

I will explain the approach for one solution, there may be many more, happy to hear them in the comments :).

Step 1: Manual GUI pipeline

Created a pipeline job from Jenkins GUI and developed the pipeline script that is required, with all the stages etc., For example:

--

--