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 信息
来源:oschina
链接:https://my.oschina.net/sh021/blog/4450826