213 shaares
2 résultats
taggé
jenkinsfile
stage("Sonar Analysis") {
steps {
println " ========== START SONAR ANALYSIS ON SOURCES ========== "
// Prepare SonarQube scanner environment
withSonarQubeEnv(sonarqubeEnvName) {
sh "mvn -B -U -Dproject.version=${version} " +
(env.BRANCH_NAME != 'master' ? "-Dsonar.branch.name=${env.BRANCH_NAME} " : "") +
" -Dsonar.value.url=${sonarqubeserver}" +
" sonar:sonar"
}
}
}
Apparemment, faire simple c'est compliqué.
Comme j'ai pas envie de le faire plusieurs fois, je le met ici, en flat :
println " ========== START PREPARATION STEP ========== "
pom = readMavenPom file: 'pom.xml'
binaryName = pom.artifactId
version = pom.version
groupId = pom.groupId
artifactoryserver = Artifactory.newServer url: 'myURL/', credentialsId: artifactoryCredentials
artifactoryserver.bypassProxy = true
println " ========== START PREPARING RELEASING ========== "
version = version.replace("-SNAPSHOT", "")
println " release version is now ${version} "
println " ========== CLONE REPO ========== "
checkout scm
def sshFolderLocation = '/root/.ssh'
def sshBitbucketKeyTargetLocation = sshFolderLocation + '/id_rsa'
configFileProvider([configFile(fileId: 'bitbucket-ssh-key', targetLocation: sshBitbucketKeyTargetLocation)]) {
withCredentials([sshUserPrivateKey(credentialsId: gitCredentialsId, keyFileVariable: 'KEYFILEVARIABLE', passphraseVariable: '', usernameVariable: gitCredentialsId)]) {
sh "git config --global user.email \"jenkins@localhost\""
sh "git config --global user.name \"jenkins\""
sh "chmod 700 ${sshFolderLocation}"
sh "chmod 600 ${sshBitbucketKeyTargetLocation}"
def current_branch = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true)
sh "git pull origin ${current_branch}"
println " ========== BUILD PACKAGE ========== "
configFileProvider([configFile(fileId: 'MAVEN_SETTINGS_FILE', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -B -U org.codehaus.mojo:versions-maven-plugin:set -DnewVersion=$version"
sh "mvn -B -U clean install -Dmaven.test.skip=true"
}
println " ========== START PUBLISHING IN DEV SPACE ========== "
publishBinaryInDevSpace(version, groupId, mavenlocaldev, binaryName, artifactoryserver, buildInfo)
sh "git add ."
sh "git commit -m \"Release version $version\""
sh "git tag $version"
def newSnapshotVersion = upgradeVersionToSnapshot(version)
configFileProvider([configFile(fileId: 'MAVEN_SETTINGS_FILE', variable: 'MAVEN_SETTINGS')]) {
sh "mvn -B -U org.codehaus.mojo:versions-maven-plugin:set -DnewVersion=$newSnapshotVersion"
}
sh "git add ."
sh "git commit -m \"Back to Snapshot version\""
sh "git push -u origin ${current_branch}"
sh "git push --tag"
println " ========== START PROMOTING STAGE ========== "
promoteArtifact(artifactoryserver, buildInfo, mavenlocaldev, mavenlocalrelease)
}
}
Avec les méthodes :
def upgradeVersionToSnapshot(currentVersion) {
println currentVersion
String[] numbersInVersion = currentVersion.split("\\.")
String minorVersion = numbersInVersion[2]
int newMinorNumber = Integer.parseInt(minorVersion) + 1
return numbersInVersion[0] + "." + numbersInVersion[1] + "." + newMinorNumber + "-SNAPSHOT"
}
def publishBinaryInDevSpace(mavenVersion, groupId, artifactoryDevSpaceName, binaryName, artifactoryserver, buildInfo) {
def packageName = groupId.replace(".", "/")
def uploadSpec = """{
"files": [{
"pattern": "target/${binaryName}-${mavenVersion}.jar",
"target":"${artifactoryDevSpaceName}/${packageName}/${binaryName}/${mavenVersion}/${binaryName}-${mavenVersion}.jar"
},{
"pattern": "pom.xml",
"target":"${artifactoryDevSpaceName}/${packageName}/${binaryName}/${mavenVersion}/${binaryName}-${mavenVersion}.pom"
}]
}"""
buildInfo = artifactoryserver.upload uploadSpec
artifactoryserver.publishBuildInfo buildInfo
}
def promoteArtifact(artifactoryserver, buildInfo, artifactoryDevSpaceName, artifactoryReleaseSpaceName) {
def promotionConfig = [
// Mandatory parameters
'buildName' : buildInfo.name,
'buildNumber' : buildInfo.number,
'targetRepo' : artifactoryReleaseSpaceName,
// Optional parameters
'comment' : 'XXXxxxXXX is promoted',
'sourceRepo' : artifactoryDevSpaceName,
'status' : 'Released',
'includeDependencies': false,
'copy' : true,
// 'failFast' is true by default.
// Set it to false, if you don't want the promotion to abort upon receiving the first error.
'failFast' : true
]
// Promote build
artifactoryserver.promote promotionConfig
}