GitLab CI 语法编写 FOR 循环语句? [英] GitLab CI syntax to write FOR loop statement?

查看:80
本文介绍了GitLab CI 语法编写 FOR 循环语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是gitlab-ci.yml文件中提到的脚本.此 GitLab CI 配置有效.但是,当 CI/CD 构建运行时,作业失败.这与 FOR 循环语法有关吗?

Below is the script mentioned in the gitlab-ci.yml file. This GitLab CI configuration is valid. But, when the CI/CD build is run, the job fails. Is it something to do with the FOR loop syntax?

deploy_dv:
  stage: deploy_dv
  variables:
    GIT_STRATEGY: none
script:
  - echo "Deploying Artifacts..."
  - echo "Configure JFrog CLI with parameters of your Artifactory instance"
  - 'c:\build-tools\JFROG-CLI\jfrog rt config --url  %ARTIFACTORY_WEBSITE% --user %ARTIFACTORY_USER% --apikey %APIKEY%'
  - 'cd ..\artifacts'
  - 'SETLOCAL ENABLEDELAYEDEXPANSION'
  - FOR %%i in (*) do (
        'c:\build-tools\curl\bin\curl.exe --header "PRIVATE-TOKEN:%HCA_ACCESS_TOKEN%" --insecure https://code.example.com/api/repository/tags/%CI_COMMIT_TAG% | c:\build-tools\jq\jq-win64.exe ".release.description" > temp.txt'
         'set /p releasenote=<temp.txt'
         'rem del temp.txt'
         'set mydate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%'
         'c:\build-tools\JFROG-CLI\jfrog rt u "%%i" %ARTIFACTORY_ROOT_PATH%/%PROJECT_NAME%/%%i --build-name=%%i --build-number=%BUILDVERSION%  --props releasenote=%releasenote%;releaseversion=%BUILDVERSION%;releasedate=%mydate% --flat=false'
     )

    - '%CURL% -X POST -F token=%REPOSITORY_TOKEN% -F ref=master  -F "variables[RELEASE]=false" -F "variables[PROGRAM]=test" --insecure https://code.example.com/api/repository/trigger'

  only:
  - /^(dv-)(\d+\.)(\d+\.)(\d+)$/

我收到以下错误:

  $ echo "Deploying Artifacts..."
"Deploying Artifacts..."
$ echo "Configure JFrog CLI with parameters of your Artifactory instance"
"Configure JFrog CLI with parameters of your Artifactory instance"
$ c:\build-tools\JFROG-CLI\jfrog rt config --url  %ARTIFACTORY_WEBSITE% --user %ARTIFACTORY_USER% --apikey %APIKEY%
Artifactory server ID [Default-Server]: $ cd ..\artifacts
$ SETLOCAL ENABLEDELAYEDEXPANSION
$ FOR %%i in (*) do ( 'c:\build-tools\curl\bin\curl.exe --header "PRIVATE-TOKEN:%HCA_ACCESS_TOKEN%" --insecure  https://code.example.com/api/repository/tags/%CI_COMMIT_TAG% | c:\build-tools\jq\jq-win64.exe ".release.description" > temp.txt' 'set /p releasenote=<temp.txt' 'rem del temp.txt' 'set mydate=%DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%' 'c:\build-tools\JFROG-CLI\jfrog rt u "%%i" %ARTIFACTORY_ROOT_PATH%/%PROJECT_NAME%/%%i --build-name=%%i --build-number=%BUILDVERSION%  --props releasenote=%releasenote%;releaseversion=%BUILDVERSION%;releasedate=%mydate% --flat=false' )
The filename, directory name, or volume label syntax is incorrect.
ERROR: Job failed: exit status 255

推荐答案

既然这个问题还没有很好的答案,我就试一试.我使用这个片段为我的存储库中的每个目录启动多个 Docker 构建.请注意 >,它允许您在 YAML 中放置多行命令(source).

Since there is still no good answer to this question, I will give it a try. I used this snippet to start multiple Docker builds for every directory in my repository. Notice the >, which lets you put multiline commands in YAML (source).

Linux 示例:

build:
  stage: loop
  script:
    - >
      for i in $(seq 1 3); do
        echo "Hello $i"
      done

Windows 示例:

Windows example:

build:
  stage: loop
  script:
    - >
      setlocal enabledelayedexpansion
      for %%a in ("C:\Test\*.txt") do (
        set FileName=%%~a
        echo Filename is: !FileName!
      )
      endlocal

这篇关于GitLab CI 语法编写 FOR 循环语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆