Jenkins: Difference between revisions

From Piszczynski
No edit summary
No edit summary
Line 47: Line 47:
     }
     }
}
}
</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>
</syntaxhighlight>

Revision as of 15:04, 11 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