When uploading files to Artifactory using the server.upload
method, you have the option of setting properties on the files. The properties are defined as part of the File Spec sent to the method. These properties can be later used to filter and download those files.
In some cases, you may want want to set properties on files that are already in Artifactory. Here properties to be set are sent outside the File Spec. To define which file to set the properties, a File Spec is used. Here's an example:
def setPropsSpec = """{ "files": [ { "pattern": "my-froggy-local-repo/dir/*.zip", "props": "filter-by-this-prop=yes" } ] }""" server.setProps spec: setPropsSpec, props: “p1=v1;p2=v2”
In the above example, the p1 and p2 properties will be set with the v1 and v2 values respectively. The properties will be set on all the zip files inside the dir directory under the my-froggy-local-repo repository. Only files which already have the filter-by-this-prop property set to yes will be affected.
The failNoOp argument is optional. Setting it to true will cause the job to fail, if no properties have been set. Here's how you use it:
server.setProps spec: setPropsSpec, props: “p1=v1;p2=v2”, failNoOp: true
The server.deleteProps method can be used to delete properties from files in Artifactory, Like the server.setProps method, it also uses a File Spec. The only difference between the two methods, is that for deleteProps, we specify only the names of the properties to delete. The names are comma separated. The properties values should not be specified. The failNoOp argument is optional. Setting it to true will cause the job to fail, if no properties have been deleted.
Here's an example:
server.deleteProps spec: deletePropsSpec, props: “p1,p2,p3”, failNoOp: true