Dynamically download files from Artifactory depending on wildcard condition

Viewed 247

I have a loop that would upload one or more files to artifactory as per below:

    if [ "${consider_kinds}" = "all" ] || [ "${consider_kinds}" = "serviceaccounts" ]
            then
                    echo "Uploading source serviceaccounts"
                    cd "${HOME}"/sync-cluster/${consider_namespace}/serviceaccounts || exit
                    for file in *.yaml
                    do
                            if [ -e "$file" ]
                            then
                                    curl --user "${deploy_user}:${deploy_user_password}" -XPUT "https://testcompany.com.au/test-virtual-repo/sync-cluster/" -H "Content-Type: application/json" -T "${file}"
                                    break
                            fi
                    done
            fi

Filename would be like this:

${BUILD_NUMBER}-${source_cluster}-${consider_namespace}-${resource}-${item}.yaml

Sample file names could be like this:

120-ntive-src-cluster-sit1-serviceaccounts-default-hssjjs.yaml
120-ntive-src-cluster-sit1-serviceaccounts-pod-labeller-abc.yaml

So, how to list the remote files(0 or 1 or more) and then download them is my question?

Had it been just a single file, I could have downloaded like below:

wget "https://testcompany.com.au/test-virtual-repo/sync-cluster/${BUILD_NUMBER}-${source_cluster}-${consider_namespace}.json"

What I don't know is how to download them dynamically! :(

1 Answers

This can be easily achieved using the JFrog CLI together file specs or AQL and by using placeholders. There are multiple examples for such a scenario in the JFrog CLI official doc.

Related