首页 > 其他 > 详细

Jenkins Pipeline Job构建配置

时间:2020-01-08 10:15:51      阅读:189      评论:0      收藏:0      [点我收藏+]

技术分享图片技术分享图片?

技术分享图片技术分享图片?

技术分享图片技术分享图片?

技术分享图片技术分享图片?技术分享图片技术分享图片?

1.创建pipeline job任务,新建任务》输入任务名称》选择“流水线”》点击【确定】

技术分享图片技术分享图片?

添加描述,This is my first test pipeline job

技术分享图片技术分享图片?

添加 pipeline脚本,点击【保存】

技术分享图片技术分享图片?

脚本解释

1. 声明脚本,添加环境变量

技术分享图片技术分享图片?

2.添加选项参数deploy_env,以及文本参数version

技术分享图片技术分享图片?

3.新建stage任务,将定义deploy_env、version参数,传入到test.properties 中

技术分享图片技术分享图片?

4.检查test.properties是否存在内容

技术分享图片技术分享图片?

5.完整脚本

#!groovy

pipeline {
    agent {node {label ‘master‘}}

    environment {
        PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
    }

    parameters {
        choice(
            choices: ‘dev\nprod‘,
            description: ‘choose deploy environment‘,
            name: ‘deploy_env‘
            )
        string (name: ‘version‘, defaultValue: ‘1.0.0‘, description: ‘build version‘)
    }

    stages {
        stage("Checkout test repo") {
            steps{
                sh ‘git config --global http.sslVerify false‘
                dir ("${env.WORKSPACE}") {
                    git branch: ‘master‘, credentialsId:"9aa11671-aab9-47c7-a5e1-a4be146bd587", url: ‘https://root@gitlab.example.com/root/test-repo.git‘
                }
            }
        }
        stage("Print env variable") {
            steps {
                dir ("${env.WORKSPACE}") {
                    sh """
                    echo "[INFO] Print env variable"
                    echo "Current deployment environment is $deploy_env" >> test.properties
                    echo "The build is $version" >> test.properties
                    echo "[INFO] Done..."
                    """
                }
            }
        }
        stage("Check test properties") {
            steps{
                dir ("${env.WORKSPACE}") {
                    sh """
                    echo "[INFO] Check test properties"
                    if [ -s test.properties ]
                    then 
                        cat test.properties
                        echo "[INFO] Done..."
                    else
                        echo "test.properties is empty"
                    fi
                    """

                    echo "[INFO] Build finished..."
                }
            }
        }
    }
}
技术分享图片

 

控制台输出

技术分享图片技术分享图片?

技术分享图片技术分享图片?

Jenkins Pipeline Job构建配置

原文:https://www.cnblogs.com/joy-sir/p/12165031.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!