Gitlab-gitlab-ci.yml无法识别7zip命令

时间:2019-10-30 14:16:59

标签: msbuild gitlab gitlab-ci gitlab-ci-runner 7zip

我刚刚开始使用Gitlab的CI / CD功能。我需要为发布的项目创建zip文件。 脚本的最后两行应该发挥作用。

    build:
        stage: build
        script:
            - echo "Testing CI CD"
            - git clone https://gitlab.io/common-dependencies.git
            - git clone https://gitlab.io/sitecore-nuget.git
            - nuget restore
            - msbuild Common.SC.sln /property:Configuration=Release
/p:PublishProfile=C:\CICDArtifacts\Artifacts_Release.pubxml


            - cd .\bin\Release
            - '"C:\Program Files\7-Zip\7z.exe" a C:\CICDArtifacts\$CI_PROJECT_NAME-$CI_JOB_ID.zip'

但是当构建触发时,出现以下错误。

enter image description here

但是,当我在Gitlab运行程序中执行以下命令时,它运行完美。

"C:\Program Files\7-Zip\7z.exe" a C:\CICDArtifacts\commonProject.zip'

似乎我在这里丢失了一些东西。请帮助我理解gitlabRunner如何理解7zechomsbuild等命令。

请注意,已安装7zip,它位于 C:\ Program Files \ 7-Zip \ 7z.exe

非常感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

我已使用以下步骤解决了该问题。

  • 更新了指向7z.exe路径的%PATH%环境变量。

  • 如下更新了脚本。

    '-7z a C:\ CICDArtifacts \ $ CI_PROJECT_NAME- $ CI_JOB_ID.zip'

  • 重新启动Gitlab运行程序,因为在更新环境变量后,Gitlab无法识别7z命令。

希望对所有人都有帮助。

答案 1 :(得分:0)

  

gitlab运行程序如何理解echo,msbuild等命令

如果其父文件夹位于%PATH%中,它应该理解它们。

如果运行不带引号的命令无效,请尝试使用其他脚本行:

- cmd /C "\""C:\Program Files\7-Zip\7z.exe" a C:\CICDArtifacts\commonProject.zip"

不带引号的形式是:没有单引号:

- "C:\Program Files\7-Zip\7z.exe" a C:\CICDArtifacts\commonProject.zip

答案 2 :(得分:0)

使用

- powershell -Command executable.exe arguments

此命令对我有用,可以启动gitlab yaml中的exe。