Search code examples
curlgitlab-ciartifactory

Gitlab-ci cannot upload all .js file to JFrog


I tried to upload all .js file from Gitlab-ci to Jfrog and I got this

curl: Can't open 'scripts/*.js'

It works if I point to a specified file (scripts/001.js)

My .gitlab-ci.yml

---
default:
  image:
    name: ubuntu:18.04
    entrypoint:
      - '/usr/bin/env'
      - 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

stages:
  - upload

job01:
  only:
    - branches
  stage: upload
  script:
    - apt update -y
    - apt install curl -y
    - curl -u $JFROG_USERNAME:$JFROG_PASSWORD -X PUT $JFROG_URL -T 'scripts/*.js'

  tags:
    - runner-aws

I tried with 'scripts/(*).js' and the same error.


Solution

  • The problem is that curl doesn't support wildcard character expansion in the -T option. This answer summarizes it nicely: https://unix.stackexchange.com/a/315431

    So the solution would be to either enumerate multiple files like this:

       - curl -u $JFROG_USERNAME:$JFROG_PASSWORD -X PUT $JFROG_URL -T "scripts/{file1.js,file2.js,file3.js}"
    

    But if there are too many files to enumerate, or the file names can change, you can use curl in combination with find (inspired by https://stackoverflow.com/a/14020013/7109330):

       - find scripts -type file -name "*.js" -exec curl -u $JFROG_USERNAME:$JFROG_PASSWORD -X PUT $JFROG_URL -T {} \;