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
Related
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.
I have a project using gradle from building and due to some recent jcenter issues, we want to move all our dependencies to our artifactory. Now i have all the configuration ready and declared inside the gradle build files. I have also removed all traces of other maven repositories.
repositories {
maven {
url "${artifactory_contextUrl}/repo_name-generic"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
After doing a gradle clean build, i expected a lot of errors as i have never added those dependencies to our artifactory repo, but none came. The project builds fine and i can see them being downloaded.
My question now is, why is it working?
Is there a way i can check from which source the dependencies are coming from?
Also in artifactories GUI i cannot locate the packages inside the specified repo
Thanks!
If you ant to print the repositories a project is using, the following task will do it for you:
task printRepos {
doFirst {
project.repositories { repositories ->
repositories.forEach { repo ->
println("${repo.name}: ${repo.url}")
}
}
}
}
If you add it to your gradle build and invoke it gradle printRepos, you should get the repositories printed out
For more information regarding the API, check: https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/RepositoryHandler.html
https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
Also thanks to Bjorn for pointing out the doFirst/doLast problem.
rm -rf ~/.gradle/caches
./gradlew assembleDebug -i > ~/Desktop/dump
search dependency lib in dump file to check where it was downloaded from
For example, flexbox-2.0.1 was downloaded from jcenter:
I'm trying to increment my pom version through Jenkins, but am facing many issues with the script element of the Jenkins declarative pipeline.
My goal is:
Jenkins pulls code from SCM
Run maven plugins
Increment version of application in the pom
Merge the new pom back into the SCM
I've managed to remove '-SNAPSHOT' from the version, and I've stored the version (e.g 1.0.0) in a variable within the script element of the pipeline. I am unable to then use that variable to be able tin increment it.
pipeline {
agent any
tools {
maven 'maven'
}
stages {
stage ('Git checkout branch') {
steps {
git branch: 'branch', credentialsId: '****', url: 'https://projectRepo'
}
}
stage ('Increment snapshot') {
steps {
dir('directory') {
//Remove snapshot from version in pom
sh 'mvn versions:set -DremoveSnapshot'
script {
//Get the version and assign to variable 'version'
version = '$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)'
}
//content of version can only be accessed by ${version}
sh "echo ${version}"
}
}
}
}
}
My aim is to get the version within the script tags, then perform a split like this .split("\."), then increment the last number, then, when I do a release, I'll use the maven flag to update the pom with the new version, plus add -SNAPSHOT to the end of the version
When you use the build-helper-maven-plugin, you can parse the version into its components:
https://www.mojohaus.org/build-helper-maven-plugin/parse-version-mojo.html
This offers not only elements like majorVersion and minorVersion, but also nextMajorVersion, nextMinorVersion etc.
I have created a Gradle plugin that creates some extra tasks and am publishing the plugin to MavenLocal with version 0.2.1. I can see the created jar in ~/.m2.
In another Gradle project, I am trying to pull in that plugin within the buildscript section of build.gradle, like this:
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath 'com.example:myplugin:0.2.+'
}
}
Running gradle tasks (or any other task, for that matter) causes Gradle to fail with the message:
> Plugin with id 'com.example.myplugin' not found.
However, if I change the version from 0.2.+ to 0.2.1 then it works. How do I get the latest version of the plugin into my project?
I just put what I did in here, and hope it helps you.
For example, I install the gradle-tomcat-plugin locally (2.4.1 and 2.4.2).
$ git checkout v2.4.2
$ ./gradlew publishToMavenLocal
$ git checkout v2.4.1
$ ./gradlew publishToMavenLocal
$ ls /Users/ruichen/.m2/repository/com/bmuschko/gradle-tomcat-plugin
2.4.1 maven-metadata-local.xml
2.4.2
And I added a separate task (showClasspath) to build.gradle to show me what is the version got applied:
task showClasspath {
doLast {
buildscript.configurations.classpath.each { println it.name }
}
}
The buildscript block is also pretty much like yours:
buildscript {
repositories {
mavenLocal()
}
dependencies {
classpath "com.bmuschko:gradle-tomcat-plugin:2.4.+"
}
}
The output is expected:
$ ./gradlew showClasspath
> Task :showClasspath
gradle-tomcat-plugin-2.4.2.jar