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.
Related
I have set the username and password for publishing to artifactory using gradle, however, the build fails on publishing the build.info.
artifactory {
publish {
contextUrl = 'http://localhost:8081/artifactory'
repository {
repoKey = "libs-snapshot-local"
username = "user"
password = "pass"
maven = true
}
defaults {
publications = ('mavenJava')
}
}
}
The user I am running gradle with doesn't have access to the artifactory repository but the user in the artifactory block does.
It seems like the build.info is being published to artifactory with the gradle user and not the user in the build.gradle.
How do I set the username/password so that the build.info is published using a user that has permissions?
There are two sets of Artifactory credentials you can configure for the Gradle Artifactory plugin:
Credentials used for artifacts resolution
repositories {
jcenter()
maven {
url "http://repo.myorg.com/artifactory/my-repo" // The Artifactory (preferably virtual) repository to resolve from
credentials { // Optional resolver credentials (leave out to use anonymous resolution)
username = "username" // Artifactory user name
password = "password" // Password or API Key
}
}
}
Credentials used for deploying artifacts and publishing build info.
This is the set of credentials you need to use for deploying the artifacts and build info into Artifactory.
You need to make sure this user has permissions for Repositories:Deploy and Builds:Deploy.
The OS user which is running gradle (gradle user) is not being used for authentication and is not recognized as an Artifactory user. It is, however, captured as part of the build info.
artifactory {
contextUrl = 'http://repo.myorg.com/artifactory' // The base Artifactory URL if not overridden by the publisher/resolver
publish {
contextUrl = 'http://repo.myorg.com/artifactory' //The base Artifactory URL for the publisher
//A closure defining publishing information
repository {
repoKey = 'my-repo' //The Artifactory repository key to publish to
username = 'stackoverflow' //The publisher user name
password = 'password' //The publisher password or API key
}
}
}
The expected behavior is that when running the following command
./gradlew clean artifactoryPublish
The build artifacts and build info will be deployed to Artifactory
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.jar
[pool-17-thread-1] Deploying artifact: http://127.0.0.1:8081/artifactory/libs-snapshot-local/gradle-example-minimal/1.0-SNAPSHOT/gradle-example-minimal-1.0-SNAPSHOT.pom
> Task :artifactoryDeploy
Deploying build descriptor to: http://127.0.0.1:8081/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under http://127.0.0.1:8081/artifactory/webapp/builds/gradle-example-minimal/1602276439713
BUILD SUCCESSFUL in 903ms
7 actionable tasks: 7 executed
In Artifactory you will see that the artifacts where deployed using the username specified in the publish section
As well as the build-info JSON file
In the build info you will see that 2 user types are being captured:
Artifactory principal - this is the Artifactory user which was used to deploy the build info
Principal - this is the OS user which was running the gradle build. This information is captured inside the build info JSON as "principal"
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 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
I would like to configure gradle with plugin for artifactory to push Android libraries. I don't have any issue with pushing aar files, but when pushing the POM I receive 409.
What went wrong: Execution failed for task ':artifactoryDeploy'.
java.io.IOException: Failed to deploy file. Status code: 409 Response message: Artifactory returned the following errors: The
target deployment path 'test/path.../0.0/name-0.0.pom' does not match
the POM's expected path prefix 'path.../0.0'
Current configuration:
artifactory {
contextUrl = "url"
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'test'
username = "test"
password = "test"
}
defaults {
publications('aar')
publishArtifacts = true
// Publish generated POM files to Artifactory (true by default)
}
}
}
I suppose there is an issue with adding repoKey before path. How can I force artifactory plugin to add repoKey ("test") before path?
My problem with build-info-extractor gralde plugin for artifactory
Source code with example for reproduce problem: https://github.com/lavcraft/gradle-artifactory-build-info-extractor-problems
Configure environment – artifactory_user artifactory_password artifactory_contextUrl
Run ./gradlew build aP
See jar artifacts properties in you artifactory instance
I expect, that this example (see below) works perfectly
artifactoryPublish {
properties = ['aa':'aaa']
properties {
nebula '**:**:**:*#*', 'not_added_prop':'sub0'
}
}
see sub0/build.gradle in github project
But it does not work. What is wrong with my example?
I think I found the cause of this issue.
Here's the artifactory closure configured in the build.gradle file, in the project you shared:
artifactory {
contextUrl = project.findProperty('artifactory_contextUrl')
publish {
repository {
repoKey = 'libs-snapshot-local'
username = project.findProperty('artifactory_user')
password = project.findProperty('artifactory_password')
}
defaults {
publications('nebula')
publishConfigs('archives')
publishIvy = false
properties {
nebula '*:*:*:*#*', 'want_to_add':'but not' // add only to *.pom artifacts. Why?
mavenJava commonProperties, '*:*:*:*#*'
}
}
}
}
As you can see above, the closure includes one publication (nebula) and one configuration (archives).
Running the build script as is prompts the following deployed artifacts:
$ gradle clean artifactoryPublish
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.pom
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.pom
Now, if you comment out the publication as follows:
//publications('nebula')
publishConfigs('archives')
You can the following:
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub0/0.1.1-SNAPSHOT/sub0-0.1.1-SNAPSHOT.jar
Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/ru/alfalab/platform/tests/sub1/0.1.1-SNAPSHOT/sub1-0.1.1-SNAPSHOT.jar
So it looks like both the archives configuration and the nebula publication contribute the same two artifacts above.
Since "want_to_add" property is configured on the nebula publication (and not on the archives publication), the 2 jars contributed by the configuration don't get the property.
A simple fix for this is issue is to remove the archives configuration:
publications('nebula')
//publishConfigs('archives')
Alternatively, if for some reason you do want to have both the configuration and publication, you can add the property to your configuration as well. Here's how you do this:
properties = ['want_to_add': 'but not']
So the full closure, with both the publication, configuration and properties for both is this:
defaults {
publications('nebula')
publishConfigs('archives')
publishIvy = false
properties = ['want_to_add': 'but not']
properties {
nebula '*:*:*:*#*', 'want_to_add':'but not' // add only to *.pom artifacts. Why?
mavenJava commonProperties, '*:*:*:*#*'
}
}
You can read more about this here:
https://www.jfrog.com/confluence/display/RTF/Gradle+Artifactory+Plugin