I am using Jenkins Artifactory plugin to deploy to an artifactory repository in my Gradle build. Since I need transitive dependency support for my artifact I need to deploy both jar and also pom.xml to artifactory.
Here is how my build.gradle looks like:
group 'com.group.name'
version '1.0'
apply plugin: 'java'
apply plugin: 'maven'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
// All of my dependencies
}
task writeNewPom << {
pom {
project {
inceptionYear '2014'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("build/poms/pom-default.xml")
}
And here is my Jenkins Config for artifactory:
Maven3-artifactory integration is checked.
And I am running this gradle tasks in my build job:
clean build writeNewPom
I am using writeNewPom task in order to create pom.xml
Problem is that only jar file is deployed but pom.xml is not being deployed to artifactory.
I tried using "include pattern" and setting is as build/libs/*.jar , build/poms/*.xml but this way even jar is not deployed.
Related
Having some maven projects. I want to change it to a scripted pipeline in jenkins
To automate the following example you can use the Jenkins API via the groovy script console or an groovy system script to create you jobs programmatically.
Example for scripted Pipeline:
node{
stage ('Build') {
git url: 'https://github.com/cyrille-leclerc/multi-module-maven-project'
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
}
}
You need the Pipeline Maven Plugin: https://wiki.jenkins.io/display/JENKINS/Pipeline+Maven+Plugin
I try to use Pipeline script and I arrive until last step.
The Pipeline script is the following code
node{
stage ('Build') {
git url: 'https://xxx#bitbucket.org/xxx/01-eureka.git'
withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'M3',
// Maven settings.xml file defined with the Jenkins Config File Provider Plugin
// Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
mavenSettingsConfig: 'my-maven-settings',
mavenLocalRepo: '.repository') {
// Run the maven build
sh "mvn clean install"
} // withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
}
}
I have already been configured the maven and Java.
I don't know the error of the last step , I update all code.
I don't exact ENV as your's, but first thing first, you should check the your Jenkins workspace folder Jenkins\workspace\docker-app, to see if the git clone works as expected
If the source code are there, manual run the maven command to see if Maven finds the pom.xml correctly
We use Sonatype Nexus as artefact repository, configured with credentials in Jenkins and it works fine.
Now i'm trying to get get a gradle project running as jenkins multibranch pipeline job using gradlew including a sonarqube code scan.
Problem:
when using only the rootProjekt.name property in settings.gradle
i get this error:
What went wrong: Plugin [id: 'org.sonarqube', version: '2.6.2'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.sonarqube:org.sonarqube.gradle.plugin:2.6.2') Searched in the
following repositories:
Gradle Central Plugin Repository
The sonarqube gradle plugin is found when using the Nexus web UI, but not by gradle inside the pipeline, seems it searches only in Gradle Central Plugin Repository.
When using a Settings.gradle like that:
pluginManagement {
repositories {
maven {
url "http://nexushost/content/groups/public/"
}
}
}
rootProject.name = 'fooBar'
it works like a charm.
How to tell gradle it should always use the sonatype nexus host without having
to configure it in settings.gradle for every Job ?
You should use a Gradle init script.
For example, in every agent, create a file USER_HOME/.gradle/init.d/use-corporate-nexus.gradle, with content:
settingsEvaluated { settings ->
settings.pluginManagement {
repositories {
maven {
url "http://nexushost/content/groups/public/"
}
}
}
}
I'm using Gradle and Jenkins and want to deploy artifacts to Artifactory. Unfortunately this deployment works only once, when I start the build in Jenkins.
If I delete the workspace and the ~/.gradle Folder on the Jenkins server the deployment works again. Deleting only the workspace alone is not enough.
Seems like a bug for me. Do I have any unknown version conflicts. Or is it something different I don't see. Thanks for any help.
Environment:
Jenkins 2.7.3
Gradle 3.1
Artifactory 4.13.0
Jenkins Artifactory Plugin 2.7.2
Gradle Build Script: (Based on example from jfrog)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.4.5')
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
repositories {
jcenter()
}
group = 'org.jfrog.example.gradle'
version = '1.0.1-SNAPSHOT'
status = 'integration'
}
artifactory {
publish {
defaults {
publishConfigs('archives')
}
}
}
// Setting this property to true will make the artifactoryPublish task
// skip this module (in our case, the root module):
artifactoryPublish.skip = true
Jenkins Artifactory Plugin Settings:
[x] Gradle-Artifactory-Integration
[x] Capture and publish build info
[x] Publish artifacts to Artifactory
[x] Publish Maven Descriptors
[x] Use Maven compatible Patterns
Rest is deactivated (not set).
Log in Jenkins (Console Output), on second run with changed version and changed source code:
Jenkins Artifactory Plugin version: 2.7.2
[Gradle] - Launching build.
[CdExampleArtifactory] $ cmd.exe /C '""C:\Program Files (x86)\Jenkins\tools\gradle-3.1\bin\gradle.bat"' --init-script c:/temp/init-artifactory8368571638486556211gradle artifactoryPublish && exit %%ERRORLEVEL%%"
:artifactoryPublish
:api:artifactoryPublish
:services:artifactoryPublish
:shared:artifactoryPublish
:services:webservice:artifactoryPublish
BUILD SUCCESSFUL
Total time: 2.422 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
Finished: SUCCESS
It looks like the task don't start the build (jar, etc.) process.
Using the latest Gradle Artifactory Plugin version 4.4.7 solves the compatibility issue with Gradle 3.1.
Gradle build snippet:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.4.7')
}
}
Note the version.
I found a solution for my problem.
I have to deactivate the gradle deamon on the jenkins server (via GRADLE_OPTS).
I have an incredibly basic Gradle build file:
plugins {
id "base"
id "com.jfrog.artifactory" version "4.3.0"
}
configurations {
batchConfig
}
artifacts{
file("dist").eachFile{ zipFile ->
batchConfig zipFile
}
}
println "BatchConfig Artifacts: " + configurations.batchConfig.allArtifacts
This is executed via Jenkins and appears to work fine:
Archives Artifacts: [DefaultPublishArtifact_Decorated
module-0.0.post0.dev6+n4c62094-py2.7:egg:egg:null]
[buildinfo] Properties file found at
'/tmp/buildInfo65481565498521.properties'
:artifactoryPublish
Deploying build descriptor to:
https://ourArtifactoryServer/artifactory/api/build
Build successfully deployed.
Browse it in Artifactory under
https://ourArtifactoryServer/artifactory/webapp/builds/testGradleBuild/34
BUILD SUCCESSFUL
However the artifact is not actually uploaded to Artifactory at all.
SSL cert configuration appears to be working fine, as I had to address that first. Any suggestions as to what I'm missing here?
Looks like you do still need to utilise the artifactory closure outlined in the Gradle Artifactory Plugin. Switching back to using "archives" instead of a custom Config and then adding this to my build sorted it:
artifactory {
publish {
defaults {
publishConfigs('archives')
}
}
}