I have a Jenkins file where one of the stage is to run the maven build. When Jenkins is running the below configuration it is stuck and it is not moving forward. This was working when I have used version 2.107.3, I have upgraded our Jenkins to 2.150.1 and I am facing this issue.
stage ('Artifactory configuration') {
steps {
script {
def SERVER_ID = "Artifactory"
def server = Artifactory.server SERVER_ID
def rtMaven = Artifactory.newMavenBuild()
rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'netstar', server: server
buildInfo = Artifactory.newBuildInfo()
rtMaven.run pom: 'pom.xml', goals: 'clean install -U -Dmaven.test.skip=true -Dmaven.javadoc.skip=true', buildInfo: buildInfo
}
}
}
`
jenkins console
There's an open bug for this: https://issues.jenkins-ci.org/browse/JENKINS-55975
Current workaround is to downgrade to following versions
git plugin = 3.9.3
git-client plugin = 2.7.6
Artifactory plugin = 2.16.2
Related
My test is working fine as Maven project. It fetches code from Git.
I wanted to execute the same in Pipeline so I wrote the below script for pipeline project.
pipeline {
agent any
stages {
stage('Getting the project from GIT') {
steps {
echo 'Pulling..';
git branch: 'main',
url: 'https://github.com/user/project.git';
}
}
stage('Cleaning the project') {
steps {
echo 'cleaning project ...'
sh 'mvn clean'
}
}
stage('Artifact Construction') {
steps {
echo "artificat contruction"
sh 'mvn package'
}
}
}
}
But when I execute , the third stage seems not to work.
Console output:
Maven configuration :
This is the version of Maven
I tried everything to solve this issue, can you guys help me? Is it a maven version problem?
You are running maven version - 3.0.5.
Maven resource plugin -3.2.0 is not compatible with this version of maven.
Upgrade maven installation to higher version. You can refer below plugin documentation page:
https://maven.apache.org/plugins-archives/maven-resources-plugin-3.2.0/plugin-info.html
I have a Jenkinsfile (see below) which runs a number of commands. I have the 'Pipeline Maven Integration' plugin installed in my Jenkins server (I have version 3_10_0 of Pipeline Maven Integration installed in Jenkins). But when I try to run my pipeline I get the error below in the console. Am I missing something? Is the error complaining about the Jenkins Maven plugin or the version of Maven in my Java solution?
Jenkinsfile:-
pipeline {
agent any
stages {
stage ('Compile Stage') {
steps {
withMaven(maven: 'maven_3_8_4') {
sh 'mvn clean install'
}
}
}
stage ('Test Stage') {
steps {
withMaven(maven: 'maven_3_8_4') {
sh 'mvn test'
}
}
}
stage ('Cucumber Reports') {
steps {
cucumber buildStatus: "UNSTABLE",
fileIncludePattern: "**/cucumber-report.json",
jsonReportDirectory: 'target'
}
}
}
}
Error in console:-
ERROR: Could not find specified Maven installation 'maven_3_10_0'.
Finished: FAILURE
Further information I have version 3.8.4 of Maven installed on the machine running the Jenkins server. I have also updated the Jenkins global tools config to reference version 3.8.4 of Maven, bit I still get the same error when running the pipeline.
I worked it out, the reference should have been as follows in the Jenkinsfile (as this is what is n my global tools):-
Is there a way to do this?. Want to publish gradle .jar in Artifactory. I was able to do a maven build with installed maven version in jenkins an publishing successfully the war in artifactory, but now devs want to move to gradle build using gradle wrapper instead of maven.
Normal Gradle build works just fine using this code.
stage('Clean Build') {
withGradle { // using gradle wrapper
sh './gradlew clean build'
}
}
But when I try to implement this with Artifactory plugin I can´t. I´m getting.
[Pipeline] ArtifactoryGradleBuild
[api-build] $ /var/lib/jenkins/workspace/api-build/gradlew --init-script /var/lib/jenkins/workspace/api-build#tmp/artifactory/init-artifactory11329321758849387716gradle clean artifactoryPublish -b ./build.gradle
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Failed to create Jar file /var/lib/jenkins/.gradle/caches/jars-8/8535adf040d7c5fdb7fd6bc28bb0ef3f/ok.
> Prefix string "ok" too short: length must be at least 3
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
this is the pipeline code:
node {
def server = Artifactory.server 'artifactory'
def rtGradle = Artifactory.newGradleBuild()
def buildInfo
jdk = tool name: 'JDK11'
//jdk = tool name: 'Java 8'
env.JAVA_HOME = "${jdk}"
stage('Get Code from Bitbucket') {
git branch: "${branch}",
credentialsId: 'jenkins',
url: 'ssh://git#bitbucket.org/project1/api1'
sh "chmod 755 gradlew"
}
stage('Artifactory Configuration') {
// Set Artifactory repositories for dependencies resolution and artifacts deployment.
rtGradle.deployer server: server, repo: 'myrepo'
rtGradle.useWrapper = true
}
stage('Gradle build') {
withGradle {
buildInfo = rtGradle.run rootDir: ".", buildFile: 'build.gradle', tasks: 'clean artifactoryPublish'
}
}
stage('Publish build info') {
server.publishBuildInfo buildInfo
}
}
Was anybody able to make this work? thank you in advance.
This issue is duplicates of this and there is also a PR fix for that which describes the root cause of the bug.
As a temporary workaround, use Gradle V6.5.1 or below.
EDIT: Sorry about formatting :( I'm new to this.. will try to clean it up.
I'm using a declarative Jenkinsfile to build and publish Maven and Gradle artifacts with buildInfo to Artifactory trying to separate each action (stage1=build, stage2=publish) in distinct stages but am unable to figure out how to do so.
Trying to figure out a working Declarative Pipeline syntax code to use with Artifactory to separate build and publishing stages. All the examples I've found are either incomplete, non-working or for scripted pipeline only.
I've tried the instructions found here https://www.jfrog.com/confluence/display/RTF/Working+With+Pipeline+Jobs+in+Jenkins
For Maven, setting 'deployArtifacts: false' in the rtMavenDeployer directive results in the buildinfo not being published, but the artifact is still deployed using goals 'clean install'.
org.jfrog.build.extractor.maven.BuildInfoClientBuilder - Deploying >artifact: xxx
In the log we see (with deployArtifacts: false):
Artifactory Build Info Recorder: publish build info set to false, build info will not be published...
steps {
rtMavenDeployer (
...
deployArtifacts: false )
in a later stage we use
rtPublishBuildInfo () to publish the actual buildInfo to Artifactory.
I've also tried to create two separate rtMavenDeployer's to be used for build and one for deploy.
for ex.
rtMavenDeployer (
id: builder
deployArtifacts: false
)
rtMavenDeployer (
id: deployer
deployArtifacts: true
)
Later references in respective build and publish stages using
BUILD STAGE:
rtMavenRun(
deployerId: 'builder'
goals: 'clean install'
)
DEPLOY STAGE:
rtMavenRun(
deployerId: 'deployer'
goals: 'install'
)
rtPublishBuildInfo()
Resulting in duplicate buildInfo in Artifactory and x2 inflated registered artifacts...
Is there a clear way for this separation of actions in a declarative pipeline?
Expect to be able to build an artifact using Declarative Pipeline syntax in one stage and deploy the actual Maven/Gradle artifact with buildInfo at a later stage.
This is how it's done in separate stages in a scripted pipeline from what I understand:
stage ('Test') {
rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean test'
}
stage ('Install') {
rtMaven.run pom: 'maven-example/pom.xml', goals: 'install', buildInfo: buildInfo
}
stage ('Deploy') {
rtMaven.deployer.deployArtifacts buildInfo
}
stage ('Publish build info') {
server.publishBuildInfo buildInfo
}
}
I ended up using something like below... although I think it's a bit ugly.
Any better solutions are very welcome!
BUILD STAGE
steps {
rtMavenRun (
tool: 'MVN-360',
pom: 'pom.xml',
goals: 'clean install',
opts: '-Dartifactory.publish.artifacts=false -Dartifactory.publish.buildInfo=false',
resolverId: 'maven-resolver',
deployerId: 'maven-deployer'
)
}
DEPLOY STAGE
steps {
rtMavenRun (
tool: 'MVN-360',
pom: 'pom.xml',
goals: 'install',
opts: '-Dartifactory.publish.artifacts=true -Dartifactory.publish.buildInfo=true',
resolverId: 'maven-resolver',
deployerId: 'maven-deployer'
)
rtPublishBuildInfo (
serverId: "Artifactory"
)
}
Plz find my code
node {
// Get Artifactory server instance, defined in the Artifactory Plugin administration page.
def server = Artifactory.server "Artifactory"
// Create an Artifactory Maven instance.
def rtMaven = Artifactory.newMavenBuild()
def buildInfo
stage('Clone sources') {
git url: 'https://github.com/jfrogdev/project-examples.git'
}
stage('Artifactory configuration') {
// Tool name from Jenkins configuration
rtMaven.tool = "Maven"
// Set Artifactory repositories for dependencies resolution and artifacts deployment.
rtMaven.deployer releaseRepo: 'libs-release-local', snapshotRepo: 'libs-release-local', server: server
rtMaven.resolver releaseRepo: 'libs-release', snapshotRepo: 'libs-release', server: server
}
stage('Maven build') {
buildInfo = rtMaven.run pom: 'maven-example/pom.xml', goals: 'clean package'
}
stage('Publish build info') {
server.publishBuildInfo buildInfo
}
}
I am using the official sample on artifactory site
https://github.com/jfrog/project-examples/blob/master/jenkins-examples/pipeline-examples/scripted-examples/maven-example/Jenkinsfile
Jobs console output
enter image description here
Unable to move beyond
"[Pipeline] artifactoryMavenBuild (hide)"
Plz help me out here...
I am able to integrate maven, artifactory in simple Maven project item but not in pipeline item on jenkins....
I had some similar issue and I switched to basics. If you are using jfrog(which you should) you can simply use the API(https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API) and hit it with curl, eg:
curl -u ${username}>:${password}# -X PUT \"${mavenRepo}/${relativeMavenPath}/${serviceName}/${serviceTag}/${serviceName}-${serviceTag}.jar\" -T ${your-jar-name}.jar
Run this command in the directory where your jar exists.