添加 Jenkins
This commit is contained in:
101
Jenkins
Normal file
101
Jenkins
Normal file
@@ -0,0 +1,101 @@
|
||||
@Library("devops") _
|
||||
def build = new org.devops.Build()
|
||||
pipeline {
|
||||
agent {label "build01"}
|
||||
options {
|
||||
skipDefaultCheckout true
|
||||
}
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
script{
|
||||
// 下载代码
|
||||
currentBuild.description = "BranchName: ${env.branchName}"
|
||||
checkout scmGit(branches: [[name: "${env.branchName}"]],
|
||||
extensions: [],
|
||||
userRemoteConfigs: [[
|
||||
credentialsId: '1f5dd05c-9c82-47da-a96d-79e28bdc2377',
|
||||
url: "${env.srcUrl}"]])
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build'){
|
||||
steps{
|
||||
script{
|
||||
//构建阶段
|
||||
build.Build()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('UniTest'){
|
||||
when {
|
||||
environment name: 'skipUnitTest',value: 'false'
|
||||
}
|
||||
steps{
|
||||
script{
|
||||
// 单元测试
|
||||
build.UniTest()
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('CodeScan'){
|
||||
steps{
|
||||
script{
|
||||
//代码扫描
|
||||
|
||||
//withCredentials([usernamePassword(
|
||||
// credentialsId: 'be40ed93-4404-4242-a95b-25ed974be409',
|
||||
// passwordVariable: 'PASSWORD',
|
||||
// usernameVariable: 'USERNAME')]) {
|
||||
// sh "sonar-scanner -Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD}"
|
||||
//}
|
||||
withSonarQubeEnv(credentialsId: '4cd3f9f5-d675-4c85-b1c9-54329bed4902') {
|
||||
sh """
|
||||
sonar-scanner -Dsonar.login=${SONAR_AUTH_TOKEN} -Dsonar.projectVersion=${env.branchName} -Dsonar.branch.name=${env.branchName}
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('PushArtifacts'){
|
||||
steps{
|
||||
script{
|
||||
// 上传制品
|
||||
def repoId="devops"
|
||||
def targetDir="devops/${JOB_NAME}/"
|
||||
def pkgPath="target"
|
||||
|
||||
def POM = readMavenPom file:'pom.xml'
|
||||
env.artifactId = "${POM.artifactId}"
|
||||
env.packaging = "${POM.packaging}"
|
||||
env.groupId = "${POM.groupId}"
|
||||
env.art_version = "${POM.version}"
|
||||
|
||||
pkgName = "${env.artifactId}-${env.art_version}.${env.packaging}"
|
||||
PushNexusArtifact(repoId,targetDir,pkgPath,pkgName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def PushNexusArtifact(repoId,targetDir,pkgPath,pkgName){
|
||||
withCredentials([
|
||||
usernamePassword(
|
||||
credentialsId: '4df0140e-023c-4b64-983d-6a2054e74228',
|
||||
passwordVariable: 'PASSWORD',
|
||||
usernameVariable: 'USERNAME'
|
||||
)
|
||||
]) {
|
||||
sh """
|
||||
curl -v -u ${USERNAME}:${PASSWORD} \
|
||||
-X POST \
|
||||
"http://192.168.0.160:8081/service/rest/v1/components?repository=${repoId}" \
|
||||
-H "accept: application/json" \
|
||||
-F "raw.directory=${targetDir}" \
|
||||
-F "raw.asset1=@${pkgPath}/${pkgName}" \
|
||||
-F "raw.asset1.filename=${pkgName}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user