【Jenkins】pipeline 相关介绍和模版适用

需求提出

jenkins 的自动化操作可以基于脚本实现,脚本主要就是pipeline的东西。在之前旧的项目中就保留着很多的源代码(jenkins的)虽然自己摸索摸索就知道了三七二十一;但是很多细节的东西依旧没有包含。

答疑解惑

由于不能直接使用公司的源码,提供如下的模版进行学习;
基本的含义和json类似,简单阅读一下就明白大概的内容是个啥。agent代理-stage阶段

pipeline{ 
        agent { 
            label 'Production' 
            } 
        stages { 
            stage('Build') { 
                steps { 
                    echo 'Building' 
                    } 
                } 
            stage('Test') { 
                steps { 
                    echo 'Testing' 
                    } 
                }
            stage('Deploy - Staging') {
                steps {
                    sh './deploy staging' sh './run-smoke-tests'
                    }
                } 
            stage('Sanity check') { 
                steps { 
                    input "Does the staging environment look ok?" 
                    }
                } 
            stage('Deploy - Production') { 
                steps {
                    sh './deploy production' 
                    }
                } 
            } 
        post { 
            always { 
                echo 'One way or another, I have finished' deleteDir() /* clean up our workspace */ 
                } 
            success { 
                echo 'I succeeeded!' 
                } 
            unstable { 
                echo 'I am unstable :/'
                } 
            failure { 
                echo 'I failed :(' 
                } 
            changed { 
                echo 'Things were different before...'
                } 
            } 
        }

其中还有一个参数parameter上诉代码中没有展示。
jenkins pipeline的parameters参数介绍
例如这样:

 parameters {
        string(name: 'BRANCH_NAME', defaultValue: "", description: "指定分支或者tag就填这里,选择分支就选下面的 BRANCH_SELECTOR")
        choice name: 'BRANCH_SELECTOR', choices: ['', 'feature/v1.9.12_open_source','feature/v1.9.11_person_certer','feature/v1.10.0'], description: ''
        string(name: 'BUILD_VERSION', defaultValue: "1.0.0", description: "版本号")

        choice name: 'BUILD_TYPE', choices: ['Release', 'Debug'], description: ''
    }

每个参数都可以对相关的py脚本起到相关作用,
例如:

class BuildExecutor:

    def __init__(self):
        self.artifact_project_name = "goapp"
        self.artifact_group_name = "public"

        self.branch_name = os.environ.get("BRANCH_NAME") + os.environ.get("BRANCH_SELECTOR")

        self.store_folder = "feature/"   # 默认存放feature目录
        for start in ['feature/', 'release/', 'customer/']:
            if self.branch_name.startswith(start):
                self.store_folder = start

通过os.environ.get进行获取。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值