batch-file - Windows 上的 GitLab runner 和处理 & %ERRORLEVEL%

标签 batch-file gitlab-ci gitlab-ci-runner findstr errorlevel

在我的 .gitlab-ci.yml 中,我尝试使用 findstr 命令。

findstr /c:"%SOLUTION_DIR%" gitlab.dif > founded.ref

如果在 gitlab.dif 中没有匹配的“%SOLUTION_DIR%”,此命令将 %ERRORLEVEL% 设置为 1。

GitLab runner 似乎将此解释为工作失败。

ERROR: Job failed: exit status 1

有什么解决方法吗?

编辑:

我的 .gitlab-ci.yml 文件

stages:
  - check
  - build

check_diff:
  stage: check
  script:
    - git diff --name-only origin/develop...HEAD > _gitlab_diff.txt
    - git diff --name-only HEAD~1 >> _gitlab_diff.txt
  artifacts:
    paths:
    - _gitlab_diff.txt
  only:
    refs:
    - merge_requests
    - develop

.generic_build_job:
  stage: build
  dependencies: 
    - check_diff
  before_script:
    - findstr /c:"%SOLUTION_DIR%" "_gitlab_diff.txt" > _check_%SOLUTION_FILE%.txt
    - for /f %%i in ("_check_%SOLUTION_FILE%.txt") do set size=%%~zi
    - if %size% == 0 exit 0
    - cd %SOLUTION_DIR%
  script:
    - '"%NUGET%" restore "%SOLUTION_FILE%"'
    - '"%MSBUILD%" /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "%SOLUTION_FILE%"'
  only:
    refs:
    - merge_requests
    - develop

MyApp1:
  variables:
    SOLUTION_DIR: "MyApp1/"
    SOLUTION_FILE: "MyApp1.sln"
  extends: .generic_build_job
  only:
    changes:
      - MyApp1/*

MyApp2:
  variables:
    SOLUTION_DIR: "MyApp2/"
    SOLUTION_FILE: "MyApp2.sln"
  extends: .generic_build_job
  only:
    changes:
      - MyApp2/*

最佳答案

我找到了使用批处理脚本的解决方法。

这是我的 skip.bat :

findstr /c:%1 %2 >nul 2>&1
if not %errorlevel% == 0 exit 0

关于batch-file - Windows 上的 GitLab runner 和处理 & %ERRORLEVEL%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55105278/

相关文章:

windows - 批处理文件。如果语句?

windows - 转义批处理脚本变量中的引号

batch-file - 如何获取当前行号?

python - rc.local shell 脚本启动时缺少文件

docker - 如何使用docker容器作为主机并在gitlab-ci上的docker容器中运行ansible?

linux - gitlab-runner 在 CI 中损坏,手动工作 - Debian 发布升级出错?

ruby-on-rails - 如何在 Gitlab CI 上修复 'Rugged::ReferenceError: revspec ' origin/master'not found'

reactjs - 我可以将环境变量从 Gitlab .gitlab-ci.yml 传递到 React 应用程序吗?

gitlab -/bin/sh : eval: line 98: bash: not found

python - 使用 GitLab CI 和 Python 'onbuild' 镜像,requirements.txt 中的包似乎没有安装