213 shaares
4 résultats
taggé
maven
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
}
hello Antichesse,
Pour rappel :
mvn release:prepare -Darguments=\"-DskipTests\"
<build>
<plugins>
<!-- java classes generation from WSDL -->
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.my.target.package</generatePackage>
<schemas>
<schema>
<fileset>
<!-- Defaults to schemaDirectory. -->
<directory>${basedir}/src/main/schemas</directory>
<!-- Defaults to schemaIncludes. -->
<includes>
<include>*.wsdl</include>
</includes>
</fileset>
</schema>
</schemas>
</configuration>
</plugin>
</plugins>
</build>
</project>
Je me met une note ici, parce que je cherche régulièrement cette feature
mvn versions:set -DnewVersion=2.50.1-SNAPSHOT
It will adjust all pom versions, parent versions and dependency versions in a multi-module project.