pipeline 语法实例三

为君一笑 提交于 2020-08-14 09:33:36

pipeline 语法实例三

按代码块优化脚本实例

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

1、源码分享如下:

pipeline {
    agent any
    options {
        ansiColor('xterm')
        timestamps()
        timeout(10)
    }

    stages {
        stage('Checkout') {
            steps {
            git branch: '${branch_name}', credentialsId: 'GitLabAccess', url:'${repo_name}'
            }
        }
        stage('Build') {
            steps {
                echo 'build'
                sh "mvn -B -e -Dmaven.test.skip=true clean compile package"
            }
        }
        stage('SonarQube') {
            steps {
                echo 'SonarQube'
                sh "mvn sonar:sonar -Dsonar.projectKey=search-ci -Dsonar.host.url=http://110.139.139.133:29090 -Dsonar.login=b9ef726d9c4c3682bbc5d94d3a8130cecf60bf33"
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploy'
                sh "cd /scm/jenkins/workspace/sonar-search-ci/search-ci/target && scp -r search-ci*.tar.gz root@110.119.155.138:/scm/deploy/scmdeploy"
            }
        }
        stage('Count') {
            steps {
                echo 'Count'
                sh """
                    /usr/bin/cloc .
                """
            }
        }
        stage('GitStats') {
            steps {
                echo 'GitStats'
                sh """
                    /usr/bin/gitstats /scm/jenkins/workspace/sonar-search-ci /scm/jenkins/workspace/sonar-search-ci/oss-search-main_rp
                """
            }
        }
    }
    /*post {
        always {
            echo 'I will always say Hello again!'
            success {
            emailext (
                subject: "Running Pipeline: ${currentBuild.fullDisplayName}",
                body: """<p>SUCCESSFUL: 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>""",
                to: "123@qq.cn",
                from: "123@163.cn",
            )
        }

        }
    }*/
}

2、搭建工程配置如下

3、执行编译后,工程页面显示效果如下

4、查看编译 log 信息

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