Jfrog uploading non-specified files - jenkins

In artifactory upload stage I have specified to upload certain text files only, but the rtUpload stage is also uploading files that are not mentioned in the file spec
{
"pattern": "*contents.txt*",
"target": "myrepo/artifacts/uploads/"
},
{
"pattern": "*md5.txt*",
"target": "myrepo/artifacts/uploads/"
}
The above code should upload only contents.txt and md5.txt files but it is also uploading files named catver.txt and mod.txt

Related

How do you extract the Artifactory path from the spec to use it later in the pipeline script

I have the below code from where I am getting to the required file in Artifactory using the regex. But I want to printout the complete path at the later stage during the pipeline script execution. Can somebody tell me how do I access the complete path that Artifactory is getting the file from?
spec: """{
"files":
[
{
"pattern": "${ARTIFACTORY_PATH}/*/some_file.txt",
"target": "./",
"flat": "true",
"sortBy": ["created"],
"sortOrder": "desc",
"limit": 1
}
]}"""

How to use artifactory query language inside a jenkins pipeline instead of having it call from a file

I have a AQL that is used to delete files from the artifactory. I am designing a pipeline so that it can delete files from artifactory based on the AQL.
I know for artifactory upload and download we can specify the AQL within the pipeline using rtupload/rtdownload, but is there a way to do for delete as well?
#AQL delete.spec
{
"files": [
{
"aql": {
"items.find": {
"repo": {"$eq":"app-java-repo"},
"path": "archives/test/app",
"type": "folder",
"$or": [
{
"$and": [
{
"name": {"$nmatch" : "*build*"}
}
]
}
]
}
}
}
]
}
jf rt del --spec delete.spec
Using the jfrog cli, the spec file can be passed and the files from artifactory repo can be deleted. This is working out manually, but how can the same be achieved by having the AQL in the pipeline stage instead of having AQL as a file.

How to properly use target of artifactory rtDownload in jenkins declarative pipeline

This snipped
stage('get iter number') {
steps {
rtDownload ( //
serverId: 'MAIN-ARTIFACTORY',
spec: '''{ "files": [{"pattern": "p1/p2/p3/${BUILD_ID}/n_iter.txt", "target": "./n_iter.txt"}] }''',
)
}
}
where BUILD_ID = 'a/b'
downloads file to a location $WORKSPACE/p2/p3/a/b/n_iter.txt rather then expected $WORKSPACE/n_iter.txt
Also, very strange - why p1 is not in downloaded path?
By default, artifacts are downloaded to the target path in the file system while maintaining their hierarchy in the source repository (not including the repository name - hence p1 is missing in your example).
To download an artifact while ignoring the hierarchy, set "flat": "true" in your file spec.
For a more advanced control of the resulting hierarchy, you may want to use Placeholders.
See more information in the File Specs documentation.
Please try with the below snippet, which means all the files in the com/my-files/ Artifactory repository-path will be downloaded into the my-folder directory on the Jenkins agent file system. For more details on this please do refer to our Declarative Pipeline Syntax wiki page here.
rtDownload (
serverId: 'Artifactory-1',
spec: '''{
"files": [
{
"pattern": "com/my-files/",
"target": "my-folder/"
}
]
In addition to the above, you can refer to the rtDownload example referred to in our GitHub page here.

Jenkins Pipeline - Upload to Artifactory: Failed to deploy file / Parent must be a folder

I have a Jenkins job which generate a zip file I want to updload to Artifactory. I have an issue setting the version of the artifact to be uploaded.
By convention, I use the timestamp has version. I want to upload file to my/group/timestamp/file.zip. The url of the file would be http://ArtifactoryAdress/foo/my/group/timestamp/file.zip
Here is my pipeline code
def serverArtifactory = Artifactory.server 'NameArtificatory'
def uploadSpec = """{
"files": [
{
"pattern": "file.zip",
"target": "my/group/${timestamp}/"
}
]
}"""
serverArtifactory.upload(uploadSpec)
I get the following error from Jenkins Job
java.lang.RuntimeException: java.io.IOException: Failed to deploy
file. Status code: 400 Response message: Artifactory returned the
following errors:
Parent my/group/timestampValue must be a folder Status code: 400
I looked around buildInfo but was not able to find how to set a version.
By the way, I am also agree with a solution without the timestamp but only group name.
Finally, this error is clear and simple.
As mentioned, a file with path my/group/timestampValue already exists. You have to delete it on Artifactory.
Don't forget it's still groovy use ${}. I used below code and it's work
def uploadSpec = """{
"files": [
{
"pattern": "**/target/*.war",
"target": "local-release/${APP_REPO}/${version.trim()}/${timestamp}.zip"
}
]}"""
server.upload(uploadSpec)
#Edit. And I just thought about it. Print please your ${timestamp}. Maybe it's contains characters with spaces, or something like this which Artifactory not allowed in directory name. Try trim your timestamp.trim()

How to create folders dynamically and upload artifacts in Jfrog artifactory using filespecs in Jenkins?

I have a build job in jenkins which builds the project from github for any branch. package will be created in build job workspace with the version as xxxx-yyyyy-2.15.0-SNAPSHOT.zip.
My next artifactory push job has filespec written as below:
{
"files": [
{
"pattern": "/var/lib/jenkins/workspace/Jobname/target/*/xxxx-yyyyy*.zip",
"target": "libs-snapshot-local/xxxx-yyyyy/",
"recursive": "false"
}
]
}
Above filespec recognize the pattern and upload the zip in libs-snapshot-local/xxxx-yyyyy/. But I need to upload the file with folder created with version name available on the zip file xxxx-yyyyy-2.15.0-SNAPSHOT.zip.
Can anybody help me to create a folder dynamically with version name? any idea on how to specify target path in filespec?
The file specs has the ability to use placeholders in order to create more flexible paths.
For example in your case:
{
"files": [
{
"pattern": "/var/lib/jenkins/workspace/Jobname/target/*/(xxxx-yyyyy*).zip",
"target": "libs-snapshot-local/{1}/",
"recursive": "false"
}
]
}
Please pay attention for the parentheses in the pattern and the placeholder marker {1} used in the target.

Resources