Jenkins Gradle build with wrapper, using artifactory plugin - gradle

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.

Related

Jenkins pipeline mvn Package command not working

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

ERROR: Could not find specified Maven installation 'maven_5_6_2'

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):-

Could not find guice-4.2.1-no_aop.jar

Could not find guice-4.2.1-no_aop.jar on a newly initialized quarkus project, not sure why we see this error. Source code is available here - https://pastebin.com/9qaTfb7D
./gradlew build
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'foo-receiver'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not find guice-4.2.1-no_aop.jar (com.google.inject:guice:4.2.1).
Searched in the following locations:
file:/Users/user/.m2/repository/com/google/inject/guice/4.2.1/guice-4.2.1-no_aop.jar
* 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
I just ran into this and was able to get past that error by modifying the generated settings.gradle file. I moved mavelLocal() to the end of the list of repositories for pluginManagement.
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
plugins {
id "${quarkusPluginId}" version "${quarkusPluginVersion}"
}
}
In my particular use case, I'm trying to create a subproject in a multi-project Gradle build. Not sure if that's related to this or not.

WildFly 18.0.1.Final - Error fetching WildFly component 'org.picketlink:picketlink-api:::2.5.5.SP12-redhat-00006'

Provision worked fine with WildFly: 16.0.x - 17.0.1.
Upgraded provision.gradle to upgrade to use wildFly 18.0.1.
plugins {
id "org.wildfly.build.provision" version '0.0.11'
}
repositories {
mavenLocal()
mavenCentral()
maven {
name 'jboss-nexus'
url "http://repository.jboss.org/nexus/content/groups/public/"
}
}
provision {
// Optional destination directory:
destinationDir = file("wildfly-as/18.0.1.Final")
configuration = file('wildfly-server-provisioning.xml')
// Define variables which need replacing in the provisioning configuration!
variables['wildfly.version'] = '18.0.1.Final'
variables['hibernate-orm.version'] = '5.3.7.Final'
variables['hibernate-search.version'] = '5.11.0.Final'
variables['hibernate-ogm.version'] = '5.4.1.Final'
}
Causes in:
MacBook-Pro:GoStopHandle NOTiFY$ gradle provision -b provision.gradle
Configure project :
Task :provision FAILED Error fetching WildFly component 'org.picketlink:picketlink-api:::2.5.5.SP12-redhat-00006' from
configured repositories; check your repository configurations to
prevent this problem. Attempting to resolve this by enabling
additional repositories automatically! Adding: [mavenLocal(),
mavenCentral() and
http://repository.jboss.org/nexus/content/groups/public/]
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':provision'.
Could not resolve all dependencies for configuration ':detachedConfiguration67'.
Could not find org.picketlink:picketlink-api:2.5.5.SP12-redhat-00006.
Required by:
project :
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
Deprecated Gradle features were used in this build, making it
incompatible with Gradle 7.0. Use '--warning-mode all' to show the
individual deprecation warnings. See
https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2s 1 actionable task: 1 executed
Any suggestions?
Deleted SDK 14 and 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home/'.
You need to add http://maven.repository.redhat.com/ga/ as repository.

Task ‘bintrayUpload’ not found in root project after update Android studio to 3.0

Before I update gradle and android studio I used to upload my library to bintray with these tasks from this tutorial:
first: gradlew install
second: gradlew bintrayUpload
But after updating android studio and gradle I had to change fist task to: gradlew installDebug
but gradle can not find taskbintrayUpload and I get this error:
* What went wrong:
Task 'bintrayUpload' not found in root project 'MyProject'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
You need to define a bintray task in your build.gradle. Since you do not have one, gradlew cannot find and therefore execute that task. Define something like the following according to your settings and you will be fine.
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
bintray {
user = ...
key = ....
publications = ....
pkg {
...
}
}
The solution was here: I had to add these lines in lib gradle.
// Place it at the end of the file
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
And it loads and adds bintray tasks to the gradle.

Resources