Overview:
- Configured master node based on CentOS 7 machine
- Configured worker node based on Ubuntu 18.04 machine
- Sample parameterized Jenkins job that executes shell script to calculate the sum of two numbers
Prerequisites:
- Sample GitHub project with public access (does not require specifying credentials in Jenkins)
- Git installed on worker node (ensure that default Git plugin is enabled in Jenkins)
- Personal access token configured on GitHub
Job configuration:
- In the Jenkins dashboard create a freestyle project job
- In job configuration go to Source Code Management --> Select Git --> Place repository URL of the GitHub project --> Specify the main branch:
- Go to the General tab and select This project is parameterized to add two numbers:
- Go to the build step and add a shell script to execute the test script from the GitHub project:
- Go to the project and press Build with Parameters to specify numbers:
- If everything is correct you should see the successful build:
Create personal access token on GitHub:
- Still, the configured job above is manually triggered, in order to automate the job execution we need to set up the webhook.
- In order to set up the webhook in Jenkins we need to have an access token for basic authentication with GitHub
- Create personal access token at https://github.com/settings/tokens/ with repo and admin hook scopes:
Configure webhook in Jenkins for GitHub project:
- Login into Jenkins dashboard and go to Manage Jenkins --> Configure System --> GitHub Server:
- Add GitHub access token with Secret Text kind:
- Press the Test connection button to check the connectivity with GitHub and select Manage hooks:
- Save the changes
- Go back to your job configuration dashboard and in Build Triggers tab select GitHub hook trigger for GitScm polling:
- In the webhooks section of the GitHub repository you will find the new added webhook:
- Clone the repository and try to test the build by pushing changes to the remote repository:
Troubleshooting tips:
- Check if the worker node is up and running
- Check if your builds in Jenkins run on the worker node by default and not the master node
- Check if the default Git plugin is installed and enabled
- Check if you specified the correct branch (e.g. main)
- Check if git is installed on the worker node