Jenkins Installation and Configuration - Dylalva/Project-CI-CD-Pipeline GitHub Wiki
📋 Requirements:
Before starting, make sure you have:
- An active Azure Subscription.
- An Azure VM with Jenkins installed and accessible.
- A Docker Hub account (or ACR) and available credentials.
- An AKS cluster created, with
kubectl
configured on Azure.
Installing Jenkins
For this project, we will use Jenkins from a Docker image, so we need to install it on the virtual machine.
1. Install Docker on the VM
sudo apt-get update
sudo apt-get install -y docker.io
2. Pull the Jenkins image
sudo docker pull jenkins/jenkins
3. Run the Jenkins container
sudo docker run -d \
--name jenkins \
-p 8080:8080 -p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkins/jenkins:lts
4. Verify if the container is running:
sudo docker ps
5. Enter the container:
sudo docker exec -u 0 -it jenkins bash
6. Install kubectl inside the container
curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mv kubectl /usr/local/bin/
7. Install az CLI inside the container
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
8. Install Docker inside the container
apt-get update
apt-get install -y docker.io
Jenkins Configuration
To configure Jenkins from your local machine, use the public IP address you use to connect to the VM and add :8080
.
You will be prompted for an initial password which you can get from the VM with the following command:
sudo docker exec -it jenkins cat /var/jenkins_home/secrets/initialAdminPassword
When you log in to Jenkins for the first time, choose to install the recommended plugins, then create your user.
Registering the Jenkins user will provide you the URL to access Jenkins, e.g., http://40.90.193.112:8080/
Creating and Configuring a Pipeline in Jenkins
-
Create a new job
- On the Jenkins Dashboard, click "Create a job" or "New Item".
- Enter the project name (for example:
ci-cd-kube
). - Select the project type Pipeline.
- Click OK.
-
Configure Git repository
- In the pipeline configuration section, under SCM, select Git.
- Enter the repository URL:
https://github.com/Dylalva/PruebasRedes.git
. - Select credentials if needed (not used in this case).
-
Configure triggers
- Under the Triggers tab, enable GitHub hook trigger for GITScm polling to automatically run the pipeline on every push.
-
Define pipeline from SCM
- In the Pipeline section, change the definition from Pipeline script to Pipeline script from SCM.
- This tells Jenkins to use a
Jenkinsfile
located in the repository to define the pipeline stages.
-
Save the configuration
- Finally, click Save or Apply to save the configuration and activate the pipeline.
Jenkins Plugins Installation Summary
-
Enter Jenkins management
- From Jenkins main panel, select Manage Jenkins.
-
Access plugins section
- Inside management, click Manage Plugins.
-
Search available plugins
- Go to the Available tab.
- Use the search bar to find plugins, e.g., search for
azure
.
-
Select and install plugins
- Select plugins to install such as Azure Credentials, Azure CLI, Docker, and Docker Pipeline.
- Click Install to start the installation.
-
Wait for installation to finish
- Jenkins will download and install the plugins.
- Once installed, configure them as necessary.
Note: If needed, restart the Jenkins docker container using:
sudo docker restart jenkins
Adding Credentials in Jenkins
-
Go to Jenkins Management
- From the main panel, select Manage Jenkins.
-
Access Credentials section
- Inside management, click Credentials.
-
Select global domain
- In credentials view, select Global credentials (unrestricted) to add credentials available globally.
-
Add new credentials
- Click Add Credentials or + Add Credentials.
-
Fill out new credential information
- For Kind, select Username with password.
- For Scope, select usually Global.
- Enter the Username and Password.
- Provide a unique ID for the credential (e.g.,
dockerhub-cred
). - Optionally add a description for easier identification.
-
Save credentials
- Click Create to save.
-
Add Azure-specific credentials
- For Kind, select Azure Service Principal.
- Add Client Secret, Tenant ID, and configure Azure environment.
- Assign a unique ID like
azure-service-principal
to be used in pipelines.
Note: Credential IDs must match those used in the
Jenkinsfile
. Note: How to obtain Azure credentials
And Done, now you have your pipeline!!