【问题标题】:How to get list of the files in a folder in gitlab-ci如何获取gitlab-ci中文件夹中的文件列表
【发布时间】:2022-12-06 18:54:20
【问题描述】:

我正在尝试在 gitlab-ci 中创建一个管道。我的问题是,当我运行 ls 命令时,我可以看到我的文件,但是当我使用条件时,我找不到相同的文件。有什么建议吗?

  script:
    - set -vux
    - ls ./dist/*
    - |
      for file in ./dist/*; do 
          if [ -f  ${file} ]; then 
              export ARTIFACTORY_IMAGE_TAG=${DATASCIENCE_REPO}/$(basename ${file})/$IMAGE_VERSION
              'curl -H "X-JFrog-Art-Api: $ARTIFACTORY_PW" -XPUT "$ARTIFACTORY_IMAGE_TAG" -T dist/$file'
          fi 
      done
  dependencies:
    - package-build

我的输出是这样的:

$ ls ./dist/*
ls ./dist/*
++ ls ./dist/__init__.py ./dist/my_proj-0.0.1.1164649-py3-none-any.whl ./dist/file1.py ./dist/file2.py ./dist/file3.json ./dist/file4.json
./dist/__init__.py
./dist/my_proj-0.0.1.1164649-py3-none-any.whl
./dist/file1.py
./dist/file2.py
./dist/file3.json
./dist/file4.json
echo $'\x1b[32;1m$ for file in ./dist/*; do  # collapsed multi-line command\x1b[0;m'
++ echo '$ for file in ./dist/*; do  # collapsed multi-line command'
$ for file in ./dist/*; do  # collapsed multi-line command
for file in ./dist/*; do 
    if [ -f  ${file} ]; then 
        export ARTIFACTORY_IMAGE_TAG=${MY_REPO}/$(basename ${file})/$IMAGE_VERSION
        'curl -H "X-JFrog-Art-Api: $ARTIFACTORY_PW" -XPUT "$ARTIFACTORY_IMAGE_TAG" -T dist/$file'
    fi 
done
++ for file in ./dist/*
++ '[' -f ./dist/__init__.py ']'
+++ basename ./dist/__init__.py
++ export ARTIFACTORY_IMAGE_TAG=https://artifactory.xyz.com/artifactory/my_proj_dev/__init__.py/0.0.1.1164649
++ ARTIFACTORY_IMAGE_TAG=https://artifactory.xyz.com/artifactory/my_proj_dev/__init__.py/0.0.1.1164649
++ 'curl -H "X-JFrog-Art-Api: $ARTIFACTORY_PW" -XPUT "$ARTIFACTORY_IMAGE_TAG" -T dist/$file'
/scripts-11718-6374270/step_script: line 239: curl -H "X-JFrog-Art-Api: $ARTIFACTORY_PW" -XPUT "$ARTIFACTORY_IMAGE_TAG" -T dist/$file: No such file or directory
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1

【问题讨论】:

    标签: shell gitlab gitlab-ci


    【解决方案1】:

    问题似乎是您没有在 for 声明中列出文件。尝试:

    for file in `ls ./dist/*`; do
        echo "act on $file" 
    done
    

    【讨论】:

      猜你喜欢
      • 2011-01-15
      • 1970-01-01
      • 2014-01-21
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      • 1970-01-01
      相关资源
      最近更新 更多