Jenkins

1. Install Java SDK

sudo apt-get install default-jre -y
sudo apt-get install default-jdk -y

2. Download jenkins

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

3. Install

sudo apt update
sudo apt install jenkins -y
sudo service jenkins start
sudo ufw allow 8080

4. Default password

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

5. Webhook URL

http://user:token@[ip]:[port]/project/[project-name]

6. Example jenkinsfile

pipeline {
    agent any
    
    environment {
        BRANCH_NAME = "${GIT_BRANCH}"
    }

    stages {
        stage('GET ENV') {
            steps {
                sh 'printenv'
            }
        }
        
        stage('Deploy to development') {
             when {
		        branch 'azibai-dev'
            }
            steps {
                echo 'Deploying.... to development'
                
                sshagent(['d969db1c-ba21-4a76-9ed5-8ea84f657315']) {
                    sh "ssh -o StrictHostKeyChecking=no [email protected] uptime"
                    sh "ssh -v [email protected] 'cd /var/www/mxyz && make'"
                }
            }
        }
        
        stage('Deploy to production') {
             when {
		        branch 'master'
            }
            steps {
                echo 'Deploying.... to production'
                
                sshagent(['597ac81d-0109-4432-ac14-3d4eee63dd34']) {
                    sh "ssh -o StrictHostKeyChecking=no [email protected] -p 29422 uptime"
                    sh "ssh -v [email protected] -p 29422 'cd /var/www/m_azibai && make'"
                }
            }
        }
    }
}

7. Install plugin

  1. SSH AGENT

  2. GITLAB TOOL

Last updated

Was this helpful?