Not able to Upload Artifacts along with their folder structure to Jfrog using Pipeline - jenkins-pipeline

I am using Pipeline Job which should upload all the jars to the Jfrog, it's working but it is uploading all the jars without its folder structure to Jfrog.
eg:
libs-release-local/one.jar
libs-release-local/two.jar
But I want to upload all the jars along with their folder structure like below.
eg:
libs-release-local/abc/efg/abc/one.jar
libs-release-local/ABC/EFG/ABC/two.jar
Note: here the folder structure may change based on the jar.
So how do I make changes in a script which will catch the folder structure and upload it for every jar?
Here is the current script am using
stage('Uploading to artifactory'){
steps{
rtUpload (
serverId:"<server id>" ,
spec: '''{
"files": [
{
"pattern": "**/*.jar",
"target": "libs-bt-test-local/"
}
]
}''',
)
}
}
Let me know if there a possible way to include a loop which will dynamically change the directory structure for every jar.

The target value can be edited with a placeholders in order to dynamically determine the uploaded path.
For example: libs-bt-test-local/{1}
For further information and examples, you may refer to the Artifactory REST API documentation page:
https://www.jfrog.com/confluence/display/JFROG/Using+File+Specs#UsingFileSpecs-UsingPlaceholders

Related

Make a simple JAR in gradle

I am new to gradle builds. I wrote a custom service for cloudera manager which needs to build a JAR file with few directories. It is a simple archive file with few directories(descriptor, images and scripts). I created it with below jar command manually.
jar -cf CSDNAME.jar descriptor images scripts
Now I want to include this as part of gradle build for which I need to write a task. I searched online where I found java related stuff which is not required in my case. Can someone help with this?
That's a code snippet using the kotlin dsl. It's based on the JAR task of the java plugin.
plugins {
java
}
tasks.jar {
doFirst {
archiveBaseName.set("CSDNAME") // By default the JAR will have the project name
from("content") // source folder where you have your content
}
}
N.B: If you already have a build file, you will need to change its extension to .kts, else you'll need of course to create one.

Various files to various destination while RPM Generation using rpm plugin in gradle

I am writing a gradle code using Gradle-ospackage RPM Plugin to generate RPM. I am able to generate RPM. My requirement is that, while generating the RPM, specific files should be moved to different location.
For Example I have below structure,
|--SOURCES
--Properties
--a.property
--b.property
--c.property
--configs
--conf.xml
--cache.xml
--war
--test.war
--testng.java
--val.java
...
...
|--SPECS
|--RPMS
|--SRPMS
In the above example, when generating rpm, *.properties,*.war and conf.xml should be moved to some other path like /modules/properties/,/modules/binaries/ and /modules/conf/.
Thanks in advance!
The nebula-ospackageplugin makes use of Gradle Copy Spec feature, which allows you to configure the "mappings" between sources directory structure and target rpm content layout, using from and into clauses. You can find several examples in the plugin documentation here and here.
In you example, you could have something like below
ospackage{
// (...)
into("/modules"){
into ("properties"){
from ("/SOURCES/Properties") // you could add some filtering
}
into ("binaries"){
from ("/SOURCES/war")
}
into ("conf"){
from ("/SOURCES/configs")
}
// EDIT : include all .java source files
into ("sources"){
from ("/SOURCES") {
include "**/*.java"
}
}
}
}

Copy to directory outside of project directory using Gradle 4.0.2

I have a gradle build which generates war file. I want to copy war file to my application servers' dropins directory which is somewhere outside of project directory. I have following copy task to do this.
task copyWarToDropins(type: Copy,dependsOn:[war]) {
from './build/libs/bds-service-token-1.0-SNAPSHOT.war'
into file('/apps/dropins') // want to copy to 'C:/apps/dropins' directory
rename { fileName -> 'bds-service-token.war' }
}
build.dependsOn copyWarToDropin
It evaluates /apps/dropins relative project directory and does copy there. I have tried many ways I can think of but could not make it copy to C:/apps/dropins directory.
Can someone please help?
First, please note that using into file(...) is redundant, as each call to into(...) will be evaluated via Project.file(...) anyhow.
As you can read in the documentation , file(...) handles strings in the following way:
A CharSequence, including String or GString. Interpreted relative to the project directory. A string that starts with file: is treated as a file URL.
So, one way to solve your problem could be using an absolute file URL.
However, if you continue to read the documentation, you will see that Java File objects are supported. So you could simply create such an object:
into new File('C:/your/absolute/path')

Download files from Artifactory to Teamcity without retaining their full path

I am using
TeamCity Enterprise 2017.1.2 (build 46812)
Artifactory Professional 5.3.1 rev 50046
Teamcity has the Artifactory plug-in installed (ver 2.3.0)
The task is simple - download files from Artifactory to Teamcity build:
From Artifactory MyRepo/RootFolder/ProjectFolder/1.2.3/<files>
To TC %checkoutdir%/artifacts/<files>
The <files> part of the path contains both folders and files and I want to retain their structure.
The download spec json is:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/",
"target": "artifacts/"
}
]
}
However, the files get downloaded into a different location than I would expect:
Actual: artifacts/RootFolder/ProjectFolder/1.2.3/<files>
Expected: artifacts/<files>
The whole path from Artifactory gets appended after the target directory. How do I tell the plugin to only use the relative path of files after the specified root? I have tried fiddling about with wildcards, slashes etc, but nothing helped.
I had to create an extra build step where I manually move files to the structure I expect, but I would prefer not to have to do that.
WORKING ANSWER:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/(*)",
"target": "artifacts/{1}",
"flat": "true"
}
]
}
You can customize your target structure by using Placeholders in your File Specs as described here.
Placeholders allow you to capture a specific section of your File Spec "pattern" property value, and use it inside the "target" property value.
In your case, the download File Spec should look like this:
{
"files": [
{
"pattern": "MyRepo/RootFolder/ProjectFolder/1.2.3/(*)",
"target": "artifacts/{1}"
}
]
}

Gradle replacing Maven assembly plugin

I'm fairly new to Gradle, and trying to port an existing Maven pom.xml that makes extensive use of maven-assembly-plugin to create various zip files.
In the example below, I'm getting files from various subdirectories (with particular extensions), and then mapping them in a flat structure to a ZIP file.
task batchZip(type: Zip) {
from fileTree('src/main/sas') {
include('**/*.sas')
include('**/*.ds')
}.files
}
This puts all the files in the root of the zip. What I ideally need though, is for the files to live under a particular path in the root of the zip, e.g. /shared/sas.
Is there a way to do this without first copying all the files to a local directory and then zipping that up?
task batchZip(type: Zip) {
into('shared/sas') {
from { fileTree('src/main/sas').files }
include('**/*.sas')
include('**/*.ds')
}
}
Have a look at the docs. It seems that if You specify appropriate into You'll get the result You're looking for.

Resources