4

In my .gitlab-ci.yml, i am trying to use the findstr command.

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

This command set the %ERRORLEVEL% to 1 if it has no match of "%SOLUTION_DIR%" in gitlab.dif.

It seems like GitLab runner is interpreting this as a job failure.

ERROR: Job failed: exit status 1

Is there any workaround?

EDIT :

my .gitlab-ci.yml file

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/*
jBravo
  • 873
  • 1
  • 9
  • 28
  • The workaround will be more easily achieved, were you to provide context for the single command line. Please expand the question code and body if you would like to give us a fighting chance of helping you with your issue. – Compo Mar 11 '19 at 15:40
  • @Compo My goal is to check for the diff in a monorepo with feature branches : https://stackoverflow.com/questions/55067521/gitlab-ci-monorepo-and-feature-branch. – jBravo Mar 11 '19 at 15:46
  • Please post only the code you need us to help you to fix, not the code you haven't written or the something in a different scripting language which you'd like to be converted to another for free. What you've posted is not Windows batch file syntax; your question was about a batch file/cmd.exe command containing `findstr`. This site is not a free conversion service, so I have removed your invalid code, please take the [tour], and read [ask] again to refresh your understanding of how this site works. – Compo Mar 11 '19 at 16:05
  • @Compo That's why I didn't ask for an help on the convertion part. I just tried to add the context as you asked me to. – jBravo Mar 11 '19 at 17:05
  • Have you considered replacing those four lines of batch file code with `Find /I "%SOLUTION_DIR%" < "_gitlab_diff.txt" && CD /D "%SOLUTION_DIR%"` – Compo Mar 11 '19 at 17:41
  • The problem here is that the gitlab runner stops on the first error encountered (string not found in the file). How can I bypass this behaviour? – jBravo Mar 12 '19 at 08:17

2 Answers2

1

I found a workaround using a batch script.

Here is my skip.bat :

findstr /c:%1 %2 >nul 2>&1
if not %errorlevel% == 0 exit 0
jBravo
  • 873
  • 1
  • 9
  • 28
-1

you can do :

  • findstr /c:%1 %2 >nul 2>&1 | exit(0)

Your job will never fail again because of this command

lampada
  • 83
  • 2
  • 9