zoukankan      html  css  js  c++  java
  • jenkins pipeline 配置

    最近在向pipeline转变, 感觉部署shell控制灵活.,

    1.首先jenkins 安装 Zentimestamp 插件后, 该插件允许自定义Jenkins      BUILD_TIMESTAMP变量的日期和时间模式。 docker build中使用时间戳做tag

    2. 安装 Timestamper 插件, 将时间戳添加到控制台输出

    3. 可以把变量提出来使用 参数化构建过程----字符参数

    4.  打开部署机api端口,实现远程调用  -H=unix:///var/run/docker.sock -H=tcp://0.0.0.0:6066  注意安全问题.

      
    pipeline {
        agent any
        options {
            timestamps()
        }
        parameters {
            string(name: 'GIT_BRANCH', defaultValue: 'sdjz_cloud_v1.0.0b', description: 'sdjz_cloud_v1.0.0b branch')
        }
        environment {
            DOCKER_REGISTRY = "192.168.20.11"
            PROJECT= 'testjiaozhou'
            APP_NAME = 'admin'
            DEPLOY_HOST = '192.168.20.157:6066'
            MAVEN = "/data/maven/bin"
            JAVAIMAGE = "192.168.20.11/source/tomcat8_jdk1.8:201909101627"
            
        }
        stages {
            stage('Checkout') {
                steps {
                    git branch: "${params.GIT_BRANCH}", credentialsId: '1111111-2222222-4855-9de1-3333333', url: 'https://code.aliyun.com/acecga-h2/api.git'
                }
            }
           stage('Build jar') {
                steps {
                    echo "1. Maven Build project jar"
                    sh '${MAVEN}/mvn -Dmaven.test.skip=true clean install'
                }
           }
           stage('Replace Dockerfile') {
                steps {
                    sh """
                            mkdir -p deployment/
                            mv -f target/*.jar deployment/${APP_NAME}.jar
                            /bin/cp /data/deployment_git/k8s-template/jar/Dockerfile deployment/
                            /bin/cp /data/deployment_git/k8s-template/jar/start.sh deployment/
                            sed -i "s#IMAGE#${JAVAIMAGE}#g"  deployment/Dockerfile
                            sed -i "s#containerport#${PORT}#g"  deployment/Dockerfile
                            sed -i "s#jenkins#${APP_NAME}#g"  deployment/Dockerfile
                    """
                }
            }
           stage('Docker Build') {
                steps {
                    sh """
                            docker build -t ${DOCKER_REGISTRY}/${PROJECT}/${APP_NAME}:${BUILD_NUMBER} deployment/
                            docker push ${DOCKER_REGISTRY}/${PROJECT}/${APP_NAME}:${BUILD_NUMBER}
                            docker rmi ${DOCKER_REGISTRY}/${PROJECT}/${APP_NAME}:${BUILD_NUMBER}
                            rm -f deployment/*.war
                    """
                }
            }        
            stage('Deploy') {
                steps {
                    input message: 'Are you sure Deployment?', ok: 'Yes'
                    sh"""
                        docker -H ${DEPLOY_HOST} rm -f ${APP_NAME} | true
                        docker -H ${DEPLOY_HOST} run -d --name ${APP_NAME} -p ${PORT}:8080 ${DOCKER_REGISTRY}/${PROJECT}/${APP_NAME}:${BUILD_NUMBER}
                    """
                    }
            }
        }
        post {
            always {
                emailext body: """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
                    <p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
                subject: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'", 
                to: ' fengjian@senyint.com'
            }
        }
    }
  • 相关阅读:
    npm
    幻灯片插件
    运用PhantomJS测试JavaScript
    C++——C++与C语言中的一些基础区别
    C++——C语言中的一些常见误区
    C++——左右值及函数重载的一些问题
    基本算法——约瑟夫环问题
    基本算法——for循环的使用之魔方阵实现
    基本算法——字符串查找之KMP算法
    基本算法——函数指针问题
  • 原文地址:https://www.cnblogs.com/fengjian2016/p/13844996.html
Copyright © 2011-2022 走看看