Explanation video: https://youtu.be/zAW2rsQFClc
Project using the Calculator repository and running in 03 Jenkins jobs.
- Job 01: The artifact of the calculator project is uploaded on Jfrog Artifactory
- Job 02: The artifact is downloaded and a packer image of this artifact is built and uploaded to a Docker Hub repository
- Job 03: The calculator image is pulled from Docker Hub and run
- Java 8 / Java 11
- Install and configure Docker
- Create a jfrog account: https://jfrog.com/start-free/#hosted
- Create a Docker Hub account: https://hub.docker.com/signup
- Pull Jfrog Artifactory docker image:
-
docker pull releases-docker.jfrog.io/jfrog/artifactory-pro:latest
-
- Create a Jfrog volume:
-
docker volume create artifactory-data
-
- Run the Artifactory Docker container:
-
docker run -d --name artifactory -p 8082:8082 -p 8081:8081 -v artifactory-data:/var/opt/jfrog/artifactory releases-docker.jfrog.io/jfrog/artifactory-pro:latest
-
- Access Jfrog: http://localhost:8082/
- Create a Repository:
- Click on Create a Repository
- Click on Create Local Repository
- Paste your license which was sent to your registered email account and save
- On Administration tab: Click on
User Management
->Users
->admin
-> Put an email and change your password - On Administration tab: Click on
Repositories
->Add Repositories
->Local Repository
->Generic
-> Name your repository, E.g.:generic-calculator-build
- Pull Jenkins docker image:
-
docker pull jenkins/jenkins:lts
-
- Create a Jenkins volume:
-
docker volume create jenkins_home
-
- Run the Jenkins container:
-
docker run --name jenkins -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):$(which docker) jenkins/jenkins:lts
-
- Give permission so that the container terminal can run docker commands
- Access the container terminal
-
docker exec -u root -it jenkins bash
-
- Give permission
-
chmod 666 /var/run/docker.sock
-
- Access the container terminal
- Access Jenkins: http://localhost:8082/
- Install suggested plugins -> Skip and continue as admin -> Verify the URL, finish and start
- Click on admin in the top of the page -> Configure -> Change the password -> Go back to Dashboard
- Create credentials: Go to
Manage Jenkins
->Manage Credentials
->Stores scoped to Jenkins
-> Jenkins -> Global credentials -> Add Credentials- Select kind Username with password and fill with you Docker Hub credentials
- Click Add Credentials again. Select kind Secret text and write your Docker Hub repository name
- Install plugins: Go to
Manage Jenkins
->Manage Plugins
->Available
-> Search and Install Packer and Artifactory - Configuring plugins:
- Gradle
- Go to
Manage Jenkins
->Global Tool Configuration
-> Gradle ->Add Gradle
- Name E.g.: gradle7 -> Install automatically -> Choose a version -> Save
- Go to
- Artifactory
- Go to
Manage Jenkins
->Configure System
-> Jfrog ->Add Jfrog Platform Instance
- Fill in Instance ID as Calculator Artifactory
- Open terminal -> Type hostname -I -> Copy first address
- Fill in JFrog Platform URL with the Jfrog URL and replace localhost with the IP copied
E.g.:http://192.168.15.99:8082/
- Fill in Default Deployer Credentials with the Jfrog credential and Test Connection
Now you should see the message: Found JFrog Artifactory
- Go to
- Packer
- Go to
Manage Jenkins
->Global Tool Configuration
-> Packer ->Add Packer
- Name as, E.g.: packer_1.8.2_linuxamd64 -> Install automatically -> Choose a version compatible with your S.O. E.g.: linux (amd64) -> Save
- Go to
- Gradle
Running with Jenkinsfiles, these following files won't be needed in Calculator project: build_image.pkr.hcl, common.yml and install-ansible.sh
- On Dashboard click in
New Item
- Set a name, choose
Pipeline
and clickOK
Choose appropriated names. E.g.: Automating_Calculator_Pipeline; Build_Calculator_Pipeline.
- Go to
Pipeline
->Definition
-> Pipeline script from SCM ->SCM
-> Git -> Paste https://github.com/Gabriely-get/Calculator_with_Jenkinsfile.git - Change the branch */master to */main
- Choose the Jenkinsfile path. The steps to create the 03 jobs are the same, the only thing that will change is the path:
- ./job-01/Jenkinsfile
- ./job-02/Jenkinsfile
- ./job-03/Jenkinsfile
The endpoints for the calculator is set by Get method and available on http://localhost:8080/calculate
For calculate is necessary provide values for: value1, value2 and operation
-
SUM: http://localhost:8888/calculate?value1=&value2=&operation=SUM
-
SUB: http://localhost:8888/calculate?value1=&value2=&operation=SUB
-
DIVISION: http://localhost:8888/calculate?value1=&value2=&operation=DIVISION
-
MULTIPLY: http://localhost:8888/calculate?value1=&value2=&operation=MULTIPLY
-
POW: http://localhost:8888/calculate?value1=&value2=&operation=POW