Install jenkins
On CentOS / RedHad based linux:
cd ~
sudo yum remove java -y
sudo yum install java-1.11.0-openjdk-devel -y
sudo yum install -y git
sudo wget -O /etc/yum.repos.d/jenkins.repo \
http://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.
key
sudo yum install -y jenkins
On Ubuntu:
sudo apt install default-jre
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
start jenkins service and set to start on boot
sudo service jenkins start
sudo chkconfig jenkins on
JenkinsFile
For jenkins pipeline you will need to add a jenkins file to your repo which will be used to configure the build when the changes are pushed to the repo.
Example of the jenkinsfile:
pipeline {
agent any
stages {
stage('Install dependencies') {
steps {
sh 'pip3 install -r requirements.txt'
}
}
stage('Start application') {
steps {
sh 'python3 app.py'
}
}
}
}
jenkins ssh keys
Jenkins will use the local jenkins user account to connect to remote repos so will need keys generated or added to the jenkins user:
create ssh key as jenkins user:
sudo -u jenkins bash # open bash shell as jenkins user
ssh-keyken # generate ssh keys
cat ~/.ssh/id_rsa.pub # display newly created public key
Jenkins cloud for docker
install docker plugin
Create cloud in jenkins
Enable remote management on docker host:
Edit the Docker service file (usually located at /lib/systemd/system/docker.service) to include the following:
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375
- Install the Docker plugin in Jenkins.
- Go to Manage Jenkins > Configure System > Cloud > Add a new cloud > Docker.
- Configure the Docker cloud with the remote Docker host URL (e.g.,
tcp://<remote-server-ip>:2375).