Eternal21
Eternal21

Reputation: 4664

How to share artifacts between gitlab-runner jobs, without exposing them for download?

I am working on a .NET configuration file for a WPF C# project. My build_job creates dlls, that my test_job needs to access. Currently I've been doing something like this:

build_job:
  stage: build
  only:
    - tags  
  script:
    - '"%NUGET_PATH%" restore'
    - '"%MSBUILD_PATH%" /p:Configuration=Release'
  artifacts:
    expire_in: 1 week
    paths:
      - "%RELEASE_FOLDER%AutoBuildWpfTest.exe"
      - "%RELEASE_FOLDER%NLog.config"
      - "%RELEASE_FOLDER%NLog.dll"
      - "%TEST_FOLDER%Tests.dll"

test_job:
  stage: test
  only:
    - tags
  script:

    - '"%NUNIT_RUNNER_PATH%" %TEST_FOLDER%Tests.dll'
  dependencies:
    - build_job

The problem with this approach is that my artifacts.zip file is now polluted with files that were only needed for testing, but are not required for actual deployment.

My question is how can I share the files between jobs without them showing up in artifacts.zip?

Also, is there any way to add files to artifacts.zip without preserving the directory tree? When building .NET projects you end up with some pretty deep directories, for example my output executables are in:

AutoBuildWpfTest\bin\Release\

, so when they get zipped up, and you try to open them, you have to go through 4 folder levels to get to the file you want. Ideally, I'd want all my output files, right in the root of artifact.zip. Thanks.

Upvotes: 1

Views: 4066

Answers (1)

Clive Makamara
Clive Makamara

Reputation: 3035

The only way I see out of this would be to get the artifacts from the test stage so maybe your .yml would look like this:

build_job:
  stage: build
  only:
    - tags  
  script:
    - '"%NUGET_PATH%" restore'
    - '"%MSBUILD_PATH%" /p:Configuration=Release'
  artifacts:
    expire_in: 1 week
    paths:
      - "%RELEASE_FOLDER%AutoBuildWpfTest.exe"
      - "%RELEASE_FOLDER%NLog.config"
      - "%RELEASE_FOLDER%NLog.dll"
      - "%TEST_FOLDER%Tests.dll"

test_job:
  stage: test
  only:
    - tags
  script:

    - '"%NUNIT_RUNNER_PATH%" %TEST_FOLDER%Tests.dll'
    - mv %RELEASE_FOLDER%AutoBuildWpfTest.exe AutoBuildWpfTest.exe 
    - mv %RELEASE_FOLDER%NLog.config NLog.config
    - mv %RELEASE_FOLDER%NLog.dll NLog.dll

  dependencies:
    - build_job
  artifacts:
    expire_in: 1 week
    paths:
      - "AutoBuildWpfTest.exe"
      - "NLog.config"
      - "NLog.dll"

Then you could download the artifacts from test_job. I know it is not ideal but the documentation doesn't show any advanced ways of dealing with individual artifacts. Also moving the files should eliminate the other problem with nested folders. I know it is also not ideal but its the only way I've found to be effective

Upvotes: 2

Related Questions