Search code examples
msbuildgitlabgitlab-cigitlab-ci-runner7zip

Gitlab - gitlab-ci.yml is not recognizing 7zip command


I just started using Gitlab's CI/CD feature. I need to create the zip file for the published items. The last two lines of the script should do the magic.

    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'

But when the build triggers, i get the following error.

enter image description here

However when i executed below command in Gitlab runner it runs perfectly.

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

It looks like i'm missing something here. Please help me to understand, how gitlab runner understands commands like 7z , echo, msbuild etc.

Please note that, 7zip is installed and it is located under C:\Program Files\7-Zip\7z.exe

Your help much appreciated.


Solution

  • I have resolved the problem using below steps.

    • updated %PATH% environment variable pointing to 7z.exe path.

    • Updated the script as below.

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

    • Restarted the Gitlab runner as, Gitlab was not able to recognize the 7z command after updating the environment variables.

    Hope it is helpful for everyone.