跳转至

99-自动化运维工具-jenkins

jenkins参数化构建过程(添加多选框)

https://blog.csdn.net/e295166319/article/details/54017231

jenkins 多选框

https://blog.csdn.net/weixin_33736649/article/details/89589656

Jenkins Pipeline(流水线) 某个任务构建失败时中止Or继续

https://blog.csdn.net/qq_40420131/article/details/115751014

DevOps流水线最佳实践

https://zhuanlan.zhihu.com/p/101693217

gitlab runner安装与使用

https://www.cnblogs.com/ws17345067708/p/10492031.html

Gitlab-runner 构建失败问题排查

https://blog.csdn.net/kjh2007abc/article/details/89717274

CentOS 安装 git2.x.x 版本

https://www.cnblogs.com/itgiser/p/11345636.html

jenkins for循环

pipeline { agent { node { label """${az}""" }

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
}
stages {
    stage('拉取远程代码'){
        steps{
          git credentialsId: '4b0b9f3c-5a14-4a03-b1f4-59ed42eb8040', url: 'ssh://git@10.255.243.15:10000/deploy-base/vcenter.git'
          dir('config') {
            git credentialsId: '4b0b9f3c-5a14-4a03-b1f4-59ed42eb8040', url: 'ssh://git@10.255.243.15:10000/deploy-base/config.git'
          }

        }
    }
    stage('推送配置文件'){
        steps{
          sh """
            shopt -s extglob
            cp -f config/${az}/${project}/vcenter/vcenter_base.conf conf/vcenter_base.conf
            shopt -s extglob
            cp -f config/${az}/${project}/vcenter/vcenter_vm_list.conf conf/vcenter_vm_list.conf

            echo ${duoxuan}
            """
///#               script{
///#                    for (item in duoxuan.tokenize(',')){
///#                        echo "Deploying to " + item
///#                    }
///#               }

        }

    }
    stage('执行剧本功能'){
         steps{
             script{
                for (item in duoxuan.tokenize(',')){
                     switch("$item"){
                         case "a":
                             stage('获取a列表'){
                                 catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                                     sh """
                                        echo a
                                     """
                                 }
                             }
                         break
                         case "b":
                             stage('获取b列表'){
                                 catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                                     sh """
                                        echo b
                                     """
                                 }
                             }
                         break
                     }
                }
             }
         }
     }
}

} ~

jenkins常用命令

远程查看jenkins任务列表
java -jar jenkins-cli.jar -s http://172.28.8.128:8080/ -auth admin:www.123 list-jobs
本地查看jenkins任务列表
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth admin:www.123 list-jobs

在开始构建之前检查SCM更改,如果没有更改,退出而不进行生成
java -jar jenkins-cli.jar -s http://172.28.8.128:8080/ -auth admin:www.123 -webSocket build test-ping -c


java -jar jenkins-cli.jar -s http://172.28.8.128:8080/ -auth admin:www.123 -webSocket build test-ping -p "az=test“
java -jar jenkins-cli.jar -s http://172.28.8.128:8080/ -auth admin:www.123 -webSocket clear-queue


java -jar jenkins-cli.jar -s http://172.28.8.128:8080/ -auth admin:www.123 -webSocket build test-ping -p "az=A-002-beijing02-test" -p "project=pe-env01" -p "job=ping" -p "host=nodes" -s -v

jenkins带颜色

需要安装

ansible插件

AnsiColor插件

        stage('执行剧本'){
            steps{
                ansiColor('xterm') {
                    sh """sh 1.sh"""
                }
                ansiColor('xterm') {
                    ansiblePlaybook colorized: true, extras: '-e "nodes=nodes"', playbook: 'ping.yml'
                }
                ansiColor('xterm') {
                    ansiblePlaybook colorized: true, extras: '-e "nodes=nodes"', playbook: 'ping.yml'
                }
            }
        }

jenkins常用插件

https://www.cnblogs.com/jpfss/p/11733340.html

image-20201207102707999

image-20201216154909412

插件下载地址:

image-20201216155001279

image-20201216155357966

jenkins slave添加

image-20201216160044434

image-20201216160117263

image-20201216160511581

image-20201216160519080

构建分支选择

image-20201216165908110

其他插件

image-20201216170821683

并发构建

image-20201216171615518

限制并发构建

image-20201216171541873