Jenkins Jenkinsfile管理 Pipeline script from SCM

1. Jenkinsfile understanding


Jenkins Pipeline provides a scalable set of tools for implementing "simple to complex" delivery processes as "continuous delivery as code". The definition of Jenkins Pipeline is usually written into a text file (called Jenkinsfile), which can be put into the source code control library of the project (that is, put the Jenkinsfile file in the code warehouse of gitlab, when Jenkins builds the task, Pull the warehouse to the local, then read the contents of the Jenkinsfile, and execute the relevant steps ).
 

 

 

2. The purpose of the experiment


Through the Jenkinsfile file, control the release of the Jenkins version. First, pull the specified remote warehouse file to the jenkins node server, then obtain the content of the Jenkinsfile file under the warehouse file, and execute the relevant content in it, such as:
1. Print the current environment variable
2. Build mirror
3, create deployment 

 

 

3. Organize the content of myblog project warehouse


1. Create a new Jenkinsfile file in the gitlab myblog project, the content is as follows: 

pipeline {
    agent { label '10.3.153.202'}      #指定在那台Jenkins节点上运行
    stages {
        stage('更新开始') {
            steps {
                echo '更新开始'
                sh 'printenv'
            }
        }
        stage('build-image') {
            steps {
                retry(2) { sh 'docker build . -t myblog:latest'}    #构建镜像
            }
        }
        stage('deploy') {
            steps {
                timeout(time: 1, unit: 'MINUTES') {sh "kubectl apply -f deploy/"     #创建deployment
                }
            }
        }
    }
}

2. Create a Dockerfile file and app.yaml in the deploy folder in gitlab myblog (the specific content is omitted) 

3. Push the files and folders created above to the gitlab warehouse

 

 

 

Four, Jenkins operation steps


1. Select "Pipeline script from SCM" in the project 

2. Select the code we want to pull

Guess you like

Origin blog.csdn.net/qq_34556414/article/details/132711783