I have a tar.gz artifact that gets uploaded to Artifactory using Jenkins. Since this artifact is not based on a Maven project, there is no pom file and thus no maven-metadata.xml being generated in Artifactory. The latter being very useful for versioning, etc.
Is there any way to have Jenkins generate a pom file for a non-Maven project?
With a manual deploy on artifactory you can generate a pom.xml ,unfortunately this option is not available on the jenkins artifactory's plugin, but you can maybe create you own shell script , like :
#!/bin/bash
groupId=com.mycompany
artifactId=myproject
version=1.0.0
echo '<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>'$groupId'</groupId>
<artifactId>'$artifactId'</artifactId>
<version>'$version'</version>
<description>Artifactory auto generated POM</description>
</project>' >> pom.xml
Anyway depending on your build tool and how you create the tar.gz package you can may be find more solutions ..
Regards
Related
I created a Junit jenkins test case where a in-memory jenkins instance is launched (as we use #Rule jenkinsrule). The code of the test case is available here.
The test case will create a FreeStyleProject (= seed job) which will use as Groovy script DSL a maven.groovy file
But when the test case is executed, the following message is reported during the the job build execution. The message reports ghe consequence of the import/parsing of the mavenJob.groovy file as the job expects that a new job will be created.
Legacy code started this job. No cause information is available
Running as SYSTEM
Building in workspace /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/workspace/test0
Processing provided DSL script
ERROR: java.io.IOException: Unable to read /var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/j h5344303144116520886/jobs/mvn-spring-boot-rest-http/config.xml
Finished: FAILURE
And of course no stack trace of the error is stdout or stderr.
How can I investigate the problem and fix it ?
Remark:
If I use the config.xml file and import it in a separate jenkins instance, the job succeeded
config.xml file generated, it looks good (vs same config.xml file created using the UI)
<?xml version='1.1' encoding='UTF-8'?>
<project>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>false</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<javaposse.jobdsl.plugin.ExecuteDslScripts>
<scriptText>mavenJob('mvn-spring-boot-rest-http') {
description 'A Maven Job compiling the project Spring Boot Rest HTTP Example'
parameters {
gitParameter {
name 'SELECTED_TAG'
description 'The Git tag to checkout'
type 'PT_TAG'
defaultValue '2.3.4-2'
branch ''
branchFilter 'origin/(.*)'
quickFilterEnabled false
selectedValue 'DEFAULT'
sortMode 'DESCENDING_SMART'
tagFilter '*'
useRepository '.*rest-http-example.git'
listSize '10'
}
}
scm {
git {
remote {
url 'https://github.com/snowdrop/rest-http-example.git'
// branch('$SELECTED_TAG')
branch('2.3.4-2')
}
}
}
rootPOM 'pom.xml'
goals 'clean install'
}</scriptText>
<usingScriptText>true</usingScriptText>
<sandbox>false</sandbox>
<ignoreExisting>false</ignoreExisting>
<ignoreMissingFiles>false</ignoreMissingFiles>
<failOnMissingPlugin>false</failOnMissingPlugin>
<failOnSeedCollision>false</failOnSeedCollision>
<unstableOnDeprecation>false</unstableOnDeprecation>
<removedJobAction>IGNORE</removedJobAction>
<removedViewAction>IGNORE</removedViewAction>
<removedConfigFilesAction>IGNORE</removedConfigFilesAction>
<lookupStrategy>JENKINS_ROOT</lookupStrategy>
</javaposse.jobdsl.plugin.ExecuteDslScripts>
</builders>
<publishers/>
<buildWrappers/>
</project>
Many thanks in advance for your help.
I created a thread discussion here too: https://groups.google.com/g/jenkinsci-users/c/mRSwARFapyA
Charles
The problem was related to many missing dependencies needed to run the test case.
I upgraded the build.gradle file and now that works.
https://github.com/ch007m/jenkins-job-dsl/blob/jenkins-2.271/build.gradle#L53-L72
BTW, the error message reported was not correlated at all to the root cause and How to fix the problem. that should be improved within the code ;-)
Trying to generate allure-report for my testng results in a Jenkins pipeline. For which I am using the allure-report maven plugin and publish-html Jenkins plugin. But the problem is the allure-report folder path is shown in double quotes (in the workspace folder structure):
"/vol_01/jenkins/workspace/Test Run/Sanity/core/target/allure-report"
That's why the htmlpublisher plugin is unable to identify the directory and is failed:
ERROR: Specified HTML directory '/vol_01/jenkins/workspace/Test Run/Sanity/core/target/allure-report' does not exist.
Even though I can open the folder and see the report properly.
pom.xml (snippet):
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.10.0</version>
<configuration>
<reportVersion>2.13.2</reportVersion>
<reportDirectory>${basedir}/target/allure-report</reportDirectory>
</configuration>
</plugin>
Jenkinsfile (snippet):
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'target/allure-report',
reportFiles: 'index.html',
reportName: 'Allure Report'
]
Any clue?
The issue seems to be with an space character in the Jenkins folder name. Jenkins (with Maven site plugin) is creating a folder path in double quotes which is not handled properly.
Need to see if I can open an issue to get this fixed (or if already fixed in latest versions).
I'm developing plugin for Atlassian Jira and trying to get the version number of my plugin to be equal Jenkins BUILD_NUMBER environment variable.
Plugin is built inside docker container using command:
docker run --rm --volume $PWD/src/jira_plugin/:/opt/atlas/ codeclou/docker-atlassian-sdk:latest atlas-package
POM.xml:
<project>
<version>${jenkins.buildNumber}</version>
...
<properties>
<jenkins.buildNumber>${env.BUILD_NUMBER}</jenkins.buildNumber>
</properties>
</project>
Result:
[INFO] Building jar: /opt/atlas/target/test-null.jar ..[ERROR] Failed
to execute goal
com.atlassian.maven.plugins:maven-jira-plugin:6.3.15:generate-obr-artifact
(default-generate-obr-artifact) on project test: Source
'/opt/atlas/target/test${env.BUILD_NUMBER}.jar' does not exist
Nevertheless command
echo `printenv`
in docker correctly displays BUILD_NUMBER var.
Question:
What should I add in pom.xml to inject BUILD_NUMBER var in pom.xml and to display version correctly?
Any help would be greatly appreciated.
I figured it out:
docker run -e BUILD_NUMBER="${BUILD_NUMBER}" ...
So the variable will be injected and can be used in pom.xml.
This is my jobs "RedeployPublisher" configuration in the config.xml. ("Deploy artifacts to the maven repository")
<publishers>
<hudson.maven.RedeployPublisher>
<id>snapshots</id>
<url>http://repo.internal.com/content/repositories/snapshots/</url>
<uniqueVersion>true</uniqueVersion>
<evenIfUnstable>false</evenIfUnstable>
</hudson.maven.RedeployPublisher>
</publishers>
but, now I need to cinfigure this in "scripted pipline" jenkinsfile.
Thank you!
I have a multi-modules project that I want to release with Jenkins. I use Maven 3.3.1, Jenkins 1.651.3 and maven-release-plugin 0.14.0
I create one job for the parent project and one job for each sub project.
Here is the parent configuration :
pom.xml :
<groupId>parent.group.id</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<url>http://mygitrepo/parent-project.git</url>
<connection>scm:git:git://mygitrepo/parent-project.git</connection>
<developerConnection>scm:git:http://mygitrepo/parent-project.git</developerConnection>
</scm>
Jenkins config :
When I perform maven release for the parent project, it works.
Now I do the same thing for a sub project.
pom.xml :
<parent>
<groupId>parent.group.id</groupId>
<artifactId>parent-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<scm>
<url>http://mygitrepo/sub-project.git</url>
<connection>scm:git:git://mygitrepo/sub-project.git</connection>
<developerConnection>scm:git:http://mygitrepo/sub-project.git</developerConnection>
</scm>
With the same Jenkins config. I got this error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:prepare (default-cli) on project sub-project: Can't release project due to non released dependencies :
[ERROR] parent.group.id:parent-artifact:pom:1.0.0-SNAPSHOT
The plugin doesn't seem to replace the parent version by the release version.
I read in the maven release plugin's documentation that I can use "-Dproject.dev" and "-Dproject.rel" to specify the parent version to use.
So I tried this :
-Dproject.dev.parent.group.id:parent-artifact=1.0.1-SNAPSHO
-Dproject.rel.parent.group.id:parent-artifact=1.0.0
release:clean release:prepare release:perform -X
-Dproject.dev.parent.group.id:parent-artifact:pom=1.0.1-SNAPSHOT
-Dproject.rel.parent.group.id:parent-artifact:pom=1.0.0
release:clean release:prepare release:perform -X
-Dproject.dev.parent.group.id:parent-artifact:pom:1.0.0-SNAPSHOT=1.0.1-SNAPSHOT
-Dproject.rel.parent.group.id:parent-artifact:pom:1.0.0-SNAPSHOT=1.0.0
release:clean release:prepare release:perform -X
None of this solve the problem.
How can I configure Jenkins plugin to set the parent-project version ?
As an alternative you could use the Versions Maven Plugin to set the parent version in an own build step:
mvn versions:update-parent
or to set a specific version
mvn versions:update-parent "-DparentVersion=[1.2.0]"