NOTE: compare the files to see the added/changes in the stages of the Jenkins pipelines. All tests are done on AWS EC2 instances (Jenkins, Nexus, SonarQube EC2 instances)
- JDK 17
- Maven 3.9.9
- Git
- SonarQube Scanner
- Nexus Artifact Uploader
- Slack Notificaiton
- Fetch Code (Using GIT plugin)
- Unit Test (
mvn test
) - Build (
mvn install -DskipTests
) - checkstyle_code_analysis (
mvn checkstyle:checkstyle
) - sonarqube_code_analysis (Using SonarQube Scanner Plugin)
- nexus_upload_artifact (Using Nexus Artifact Uploader Plugin) [OPTIONAL - Use AWS ECR]
- docker build
- upload to elastic container service
- slack_notification (Using Slack Notification Plugin) [ALWAYS]
Steps:
- Repo Settings -> Create GitHub Webhook ->
http://<jenkins-ip>:8080/github-webhook/
(Make sure Jenkins server allows traffic from anywhere on port 8080) - Pipeline Configure -> Enable GitHub hook trigge fir GITScm Polling
Steps:
- Enable Poll SCM on pipeline configuration.
- Define cron job to check the GitHub commit at which interval.
Steps:
- Enable Build Periodically on pipeline configuration.
- Define a cron job and the pipeline will trigger at that specific time regularly.
- Example:
30 20 * * 1-5
triggers pipeline at 8:30PM Monday to Friday. (SEC HR DOM MONTH DOW)
- Create a token
<remote-build-token>
from the pipeline configuration.
JENKINS_URL/job/build-trigger/build?token=TOKEN_NAME
username:token
wget -q --auth-no-challenge --user <username>
--password <password>
--output-document - ' http://<jenkins-ip>
:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)
Jenkins-Crumb:<crumb>
curl -I -X POST http://username:token@`:8080/job/build-trigger/build?token=
-H "Jenkins-Crumb:
`"
We can run the job using the above URL from anywhere, bash scripts, Python, Ruby, Ansible, any programming language.