I need to write an yaml script to get the most recent artifact from artifact repository and store it in a windows server.
Repository Browser Structure would be like the below
Name of the Repo - Generic_App
TEST_APP is a folder inside the repo.
Generic_App->TEST_APP->1->TEST_APP-1.ZIP
Generic_App->TEST_APP->2->TEST_APP-2.ZIP
Generic_App->TEST_APP->3->TEST_APP-3.ZIP
Can you help me with the script to download TEST_APP-3.ZIP
You requested for a yaml script. I guess it'll be easy for you to embed the following command in any script you may be using.
The following JFrog CLI command downloads the latest file from Artifactory, which matches your requirements. The command will look for the newest file created, which path and name matches the following pattern (notice the wildcard in the file name pattern) -
Generic_App/TEST_APP/TEST_APP-*.ZIP
jfrog rt dl "Generic_App/TEST_APP/TEST_APP-*.ZIP" --sort-by created --sort-order desc --limit 1 --url "<artifactory url>" --user "<artifactory username>" --password "<artifactory password>"
Note: In most cases, the Artifactory URL ends with /artifactory
If the machine which runs the script doesn't have JFrog CLI installed, here's how you can install it - https://jfrog.com/getcli/
Related
I'm trying to retrieve the latest version of a artifact from artifactory, but there is a file "maven-metadata.xml" in the target directory that is always being returned.
Is there a way for the request to exclude the file? My current request looks as follows:
"https://artifactory/api/storage/pathtodirectory?lastModified"
This returns the maven-metadata.xml file, I tried modifying the request to:
"https://artifactory/api/storage/pathtodirectory?lastModified?archiveType!=xml"
But that didn't exclude the file.
You have the option of retrieving the latest artifact which was modified, while also excluding patterns of files, using JFrog CLI.
Here's how you do it:
jfrog rt s repo-name/path/to/directory/ --sort-by modified --sort-order desc --limit 1 --exclusions "*maven-metadata.xml"
Notice that the source path argument ends with a slash (...directory/), to indicate that yuo wish to retrieve the content of the directory folder in Artifactory.
You can modify the source path argument and also the value of the --exclusions option to include wildcards, and also change the value of the --limit option to return the X last modified artifacts.
Once you're satisfied with the output, and you want to download the artifact, simply replace jfrog rt s with jfrog rt dl.
How does the config file provider plugin work?
I have a Jenkinsfile for a declarative pipeline (multi-branch build) that contains:
configFileProvider([configFile(fileId: 'maven-settings', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -B -s $MAVEN_SETTINGS -DWHERE="$WHERE" deploy'
}
I have tried running this on two different Jenkins installations one which is installed directly and runs as daemon and another running as a container (jenkinsci/blueocean).
When run on the direct the Jenkins Config File Provider plugin is able to provide the required settings.
provisioning config files...
copy managed file [Maven settings] to file:/var/lib/jenkins/workspace/redacted#tmp/config8989354118161621860tmp
When run under the jenkinsci/blueocean container it fails with:
provisioning config files...
not able to provide the file [ManagedFile: id=maven-settings, targetLocation=null, variable=MAVEN_SETTINGS], can't be resolved by any provider - maybe it got deleted by an administrator
I have created a managed maven-settings.xml file with id maven-settings for blue/ocean but it is not being picked up.
I've also tried copying it to ~/.m2/settings.xml
By contrast the working installation does not have any managed files (settings.xml or otherwise) and I am unable to locate any maven settings file in the workspace. I'm not sure what the #tmp directory is. It is deleted by the time a build finishes.
So my question is:
Where should I put the settings to make the configFileProvider pass them on for the jenkinsci/blueocean build job?
How does the config file provider plugin work?
I have no idea what its doing so its hard to debug. The source is here but Java, Maven & Jenkins are not my main area.
What differences are there when Jenkins itself run as a container?
This answer suggests the the config file provider is unnecessary.
There is a similar question which is unanswered but it relates to a maven plugin.
I have part of the answer. My maven-settings file wasn't being picked up because I was using the file name rather than the file Id which is different.
The remaining part of the question is how is the original Jenkins instance able to generate this file without it being listed as a managed file.
I need download artifact level folder from artifactory on shell script. I have found some same topics but I not found solution. Please give me solution.
A tip for non PRO users:
Through the GUI go to the repository path (e.g. http://artifactory.mycompany.com:8081/artifactory/list/libs-release-local/path/to/my/folder/
Use the folder to recursively WGET the contents (e.g. wget -r --no-parent -nH --cut-dirs=4 --proxy=off http://artifactory.mycompany.com:8081/artifactory/list/libs-release-local/path/to/my/folder/)
When using the PRO version of Artifactory you can use this REST API for downloading a complete folder.
I created a job in jenkins with maven for my java project. My jar name is
artifactId-version.jar and I am deploying this jar to artifactory server. I
have 5 to 6 jar files like this which are deployed to artifact.
My build command is
clean install -Dversion=$BUILD_NUMBER -Denv=r -DskipITs
so that my jar is like example-r-23.jar and under execute shell I have written as
echo $BUILD_NUMBER > src/sonarCharts/latest.txt
and sending this file to Artifactory. I am using curl command to read the
value in latest.txt file and downloading jar file.I am downloading them from
my code through shell script (using wget command like wget --user --
password http://artifactory/example-1.0.jar).
This process repeats for every release. Once i deliver my code to production,
i am changing this version to 2.0 and now jar file will be like example-
2.0.jar and deploying it to artifact.I need to change my script file every
time jar version is changed.
<artifactId>rabbitMQHandler</artifactId>
<version>1.0</version>
<name>rabbitMQHandler</name>
<url>http://maven.apache.org</url>
I followed one procedure by overwriting the version with Build number and
passing it from command line as
mvn clean install -Dversion=$BUILD_NUMBER --- to build
and i am sending this BUILD_NUMBER to one txt file as
echo $BUILD_NUMBER > latest.txt --- sending this to artifactory
and placing that file in artifactory. I am reading that txt file through shell
script using curl and i am using that number in wget command.
I feel my way of doing is not correct and is there any other way of doing it.
Is it possible to run mvn commands if there is no maven installed on the target machine? I know this is a strange one.
Is this possible using some wrapper tool/utility which has maven/etc tools inbuilt in the wrapper tool/utility?
This is what I'm trying to achieve. Using Ansible (and Maven) to get an artifact to a given folder from a remote Artifactory server.
I want to download an artifact from Artifactory.
The target machine doesn't have maven(mvn) installed.
If I create a small one liner shell script then I have to deal with all the repositories one by one i.e. in some order (i.e. look into release repo first, then way down to snapshot etc or vice versa).
(wget http://myArtifactoryServer:somePort/artifactory/libs-snapshot-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-stage-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-alpha-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-beta-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-gamma-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-release-local/comcompany/product/artifactName/version/artifactNameVersion.extension )
I was wondering if there's any other easiest way I can grab an artifact by just giving "virtual repo name" i.e. libs-release (which I have created and looks into all physical release repos or just use company-repos virtual so that I don't have to name each repo name one by one using || or with wget).
I don't have to use wget either if there's any other way around. Maven automatically finds the artifact and search in all the repos (what you define in settings.xml or pom.xml or at command line maven-dependency-plugin:get/copy)
I can also write code in groovy but then groovy has to be there on the target server.
Late to the party, but nonetheless:
Having re-read the question, what you're missing is, as you mention, a virtual repo, which combines repos so they appear to be one. Artifactory supports this out of the box.
As an alternative to maven that requires nothing other than bash, you could try this shell script from sonatype http://blog.sonatype.com/2011/01/downloading-artifacts-from-nexus-with-bash.