Search code examples
githubjenkinscontinuous-integrationjenkins-pipelinecontinuous-deployment

Integrate the script and parameterised build code in Jenkins pipeline item to github


I have centralized deployment that is created as a "pipeline" item on Jenkins.

All of the services can be deployed from UAT to PRD using this pipeline.

How it works:

This pipeline has the feature of:

  • Parameterised build
    • You can select "Service" <- provides dropdown of different services
    • Depending on the service, you can see the corresponding "Source location"(UAT server), and "Destination"(PRD server) <- a list of if else cases configured in Jenkins
  • the pipeline itself: put as a script for this pipeline item

Problem:

There is:

  • No version control
  • The script only stored in Jenkins. In case we lose Jenkins, the script will be gone.
  • Whenever we update, we update the script on Jenkins directly (work on it on VS code, copy & paste it to this Jenkins item)

Question:

  • How to/ Is it possible to store the groovy script & parameterised build code on github repo and have them auto-update the Jenkins pipeline directly?

Any help will be greatly appreciated.


Solution

  • Within the Jenkins pipeline configuration menu, you can indicate a GitHub repository to pull and execute the Jenkinsfile script from, like shown below.

    Then, if you want your pipeline script to run on every git push, you must setup a webhook within your GitHub repository that points to the Jenkins URL, and finally, activate the GitHub hook trigger for GITScm polling checkbox in the pipeline configuration menu.

    Do not forget to have the GitHub plugin installed.

    enter image description here

    enter image description here