pipeline 语法实例二

故事扮演 提交于 2020-07-28 16:55:17

pipeline 语法实例二

Node 前端 We b页面, npm 是 JavaScript 的包管理工具。

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*

pipeline {
    agent any
    options {
        timestamps()
        timeout(10)
    }
    stages {
        stage('Checkout') {
            steps {
            git branch: '${branch_name}', credentialsId: 'GitLabAccess', url:'${repo_name}'
            }
        }
        stage('Build') {
            steps {
                nodejs('nodejs_12.9.1'){
                    sh "npm install"
                    sh "npm run build"
                    //sh "npm run build:physics"
                }
            }
        }
        /*stage('Package') {
            steps {
                sleep 1
                sh """
                    cd /home/jenkins/workspace/jenkins-quality-front-ci
                    if [ -d "quality-front" ]; then
                       rm -rf quality-front
                    fi
                    sleep 1
                    if [ -f "quality-front.tar.gz" ]; then
                       rm -rf quality-front.tar.gz
                    fi
                    sleep 1
                    mkdir quality-front
                    sleep 2
                    cp -rf dist scripts template quality-front
                    sleep 2
                    tar -zcvf quality-front.tar.gz  quality-front
                """
                
            }
        }*/
        stage('Deploy') {
            steps {
                sh "cd /home/jenkins/workspace/jenkins-quality-front-ci && scp -r quality-front*.tar.gz root@110.119.151.131:/opt/web-front/scmdeploy"
                sh "ssh -tt root@110.119.151.131 cp -rf /opt/web-front/quality-front /opt/web-front/scm-backup/"
                sh "ssh -tt root@110.119.151.131 rm -rf /opt/web-front/quality-front/dist/*"
                sleep 1
                sh "cd dist && scp -r * root@110.119.151.131:/opt/web-front/scmdeploy/quality-front/dist/"
                sh "ssh -tt root@110.119.151.131 cp -rf /opt/web-front/scmdeploy/quality-front/dist/* /opt/web-front/quality-front/dist/"
                sleep 1
                sh "ssh -tt root@110.119.151.131 cp -rf /opt/web-front/config-jsbak/quality-front/config.js /opt/web-front/quality-front/dist/"
                //sleep 1
                //sh "ssh -tt root@110.119.146.100 chmod -R 755 /opt/web-front/quality-front/dist"
            }
        }
        
        stage("SendMail") {
            steps{
                script {
                    mail to: '123@qq.cn',
                    cc: '123@163.cn',
                    charset : 'UTF-8',
                    mimeType : 'test/plain',
                    subject: "Running Pipeline: ${currentBuild.fullDisplayName}",
                    body: "Something is wrong with : ${env.BUILD_URL}, just for test send mail via pipeline code"
                }
            }
        }
        
        /*stage('show gitstats') {
            steps {
                sh "/usr/bin/cloc . && pwd"
                //sh "/usr/bin/gitstats ${WORKSPACE}/ ${WORKSPACE}/jenkins-quality-front-ci_rp20191104"
            }
        }*/
        
        /*stage("send mail test") {
            steps{
                script {
                    mail to: '123@qq.cn',
                    subject: "Running Pipeline: ${currentBuild.fullDisplayName}",
                    body: "Something is wrong with : ${env.BUILD_URL}"
                }
            }
        }*/
    }
    
    /*post {
        failure {
            mail to : '123@qq.cn',
            subject : "Failed Pipeline: ${currentBuild.fullDisplayName}",
            body : "Something is wrong with ${emv.BUILD_URL}"
        }
    }*/
   
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!