(Created page with "== Install jenkins == <syntaxhighlight lang="bash"> 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 </syntaxhighlight>start jenkins service and set to start on boot<syntaxhighlight lang="bash"> sudo service jenkins start sudo ch...") |
No edit summary |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Install jenkins == | == Install jenkins == | ||
<syntaxhighlight lang="bash"> | On CentOS / RedHad based linux:<syntaxhighlight lang="bash"> | ||
cd ~ | cd ~ | ||
sudo yum remove java -y | sudo yum remove java -y | ||
| Line 10: | Line 10: | ||
key | key | ||
sudo yum install -y jenkins | sudo yum install -y jenkins | ||
</syntaxhighlight>start jenkins service and set to start on boot<syntaxhighlight lang="bash"> | </syntaxhighlight>On Ubuntu:<syntaxhighlight lang="bash"> | ||
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 | |||
</syntaxhighlight> | |||
start jenkins service and set to start on boot<syntaxhighlight lang="bash"> | |||
sudo service jenkins start | sudo service jenkins start | ||
sudo chkconfig jenkins on | sudo chkconfig jenkins on | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== 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:<syntaxhighlight lang="bash"> | |||
pipeline { | |||
agent any | |||
stages { | |||
stage('Install dependencies') { | |||
steps { | |||
sh 'pip3 install -r requirements.txt' | |||
} | |||
} | |||
stage('Start application') { | |||
steps { | |||
sh 'python3 app.py' | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
== 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:<syntaxhighlight lang="bash"> | |||
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 | |||
</syntaxhighlight> | |||
== 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:<syntaxhighlight lang="bash"> | |||
ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375 | |||
</syntaxhighlight> | |||
* 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., <code>tcp://<remote-server-ip>:2375</code>). | |||
Latest revision as of 10:00, 13 September 2024
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).