我正在尝试在gitlab-ci中创建一个管道。我的问题是当我运行ls命令时,我可以看到我的文件,但当我使用for condition时,我找不到相同的文件。有什么建议吗?
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
更新1:根据我收到的错误,我认为在我的curl命令系统不能文件的文件。但为什么我不确定?
2条答案
按热度按时间kulphzqa1#
简单语法错误。
该错误指出存在
No such file or directory
。一个实验。
让我们在终端中运行这三个命令。
第一个
(请勿删除任何报价。)
结果以
bash
为单位结果以
zsh
为单位终端将单引号字符串识别为第一个命令中的命令。
第二个
(请勿删除任何报价。)
结果以
bash
为单位结果以
zsh
为单位终端将带有斜杠的单引号字符串识别为第二个命令中的文件。
第三个
没有一个引号。
结果是
如果要在每个循环中运行
curl
命令,只需去掉单引号。
该解决方案
nfzehxib2#
问题似乎是您没有在
for
语句中列出文件。请尝试: