使用jenkins pipeline插件构建一个job,主要是:从gitlab拉取代码–编译–sonar分析–quality gate判断是否通过质量阀
脚本如下:
node {
def mvnHome
stage(‘Preparation’) { // for display purposes
// Get some code from a GitHub repository
git branch: ”, credentialsId: ”, url: ”
// Get the Maven tool.
// ** NOTE: This ‘M3’ Maven tool must be configured
// ** in the global configuration.
mvnHome = tool ‘maven’
}
stage(‘Build’) {
// Run the maven build
if (isUnix()) {
sh “’{mvnHome}/bin/mvn’ clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true”
} else {
bat(/”{mvnHome}/bin/mvn’ clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true” } else { bat(/”{mvnHome}\bin\mvn” clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true/)
}
}
stage(‘Sonar’) {
withSonarQubeEnv(‘sonar’){
if (isUnix()) {
sh “’{mvnHome}/bin/mvn’ sonar:sonar”
} else {
bat(/”{mvnHome}/bin/mvn’ sonar:sonar” } else { bat(/”{mvnHome}\bin\mvn” sonar:sonar/)
}}
}
sleep(10)
stage(‘Quality Gate’) {
timeout(3) {
def qg = waitForQualityGate()
echo “—before qg:q
初识jenkins pipeline
最新推荐文章于 2025-03-16 22:32:11 发布
本文介绍了如何利用Jenkins Pipeline构建一个自动化流程,包括从GitLab获取代码、使用Maven进行编译、SonarQube分析以及通过Quality Gate确保代码质量。通过具体的Pipeline脚本,展示了每个阶段的实现细节,如设置Maven工具、运行Maven命令、执行SonarQube扫描和等待质量门检查。

最低0.47元/天 解锁文章
1319

被折叠的 条评论
为什么被折叠?



