简体   繁体   English

如何将带有工件的 GitLab CI Linux 作业中的变量传递给使用 shell-windows-runner 执行的作业

[英]How to pass variable from GitLab CI Linux job with artifacts to a job which, is executed with shell-windows-runner

I have two jobs on a GitLab pipeline: In the first one I save a value into a txt file in order to share this value through an artifact to the next job.我在 GitLab 管道上有两个作业:在第一个作业中,我将一个值保存到一个 txt 文件中,以便通过工件将这个值共享给下一个作业。 The second one is a do.net job and I would like to get the value from the txt file I populated in the job1 an save this value into a variable.第二个是 do.net 作业,我想从我在 job1 中填充的 txt 文件中获取值,并将该值保存到一个变量中。

stages:
  - stg1
  - stg2

job1:
  stage: stg1
  script:
    - echo ${NEW_VERSION} > build.txt
  artifacts:
    expire_in: 1 week
    paths:
      - build.txt
  variables:
    NEW_VERSION: "1.2.3"
      
job2:
  stage: stg2
  needs: [job1]
  tags:
    - dotnet
  script:
    # Here I need to get value from build.txt and set it into the $NEW_VERSION variable
    - '& "$NUGET_PATH" dotnet restore'
    - '& "$MSBUILD_PATH" /nologo /p:Configuration=Release'
    - 'mkdir target'
    - 'Add-Type -assembly "system.io.compression.filesystem"'
    - '[io.compression.zipfile]::CreateFromDirectory("$CI_PROJECT_DIR\$EXE_RELEASE_FOLDER\", "$CI_PROJECT_DIR\target\$PACKAGE_NAME-$NEW_VERSION.zip")'   
  artifacts:
    expire_in: 1 week
    paths:
      - build.txt
  dependencies:
    - job1 
  variables:
    NEW_VERSION: ""

Finally I found the solution to the problem by using '$NEW_VERSION=type.\build.txt' so the final YAML would be:最后,我通过使用'$NEW_VERSION=type.\build.txt'找到了问题的解决方案,因此最终的 YAML 将是:

stages:
  - stg1
  - stg2

job1:
  stage: stg1
  script:
    - echo ${NEW_VERSION} > build.txt
  artifacts:
    expire_in: 1 week
    paths:
      - build.txt
  variables:
    NEW_VERSION: "1.2.3"
      
job2:
  stage: stg2
  needs: [job1]
  tags:
    - dotnet
  script:
    - '$NEW_VERSION=type .\build.txt'
    - '& "$NUGET_PATH" dotnet restore'
    - '& "$MSBUILD_PATH" /nologo /p:Configuration=Release'
    - 'mkdir target'
    - 'Add-Type -assembly "system.io.compression.filesystem"'
    - '[io.compression.zipfile]::CreateFromDirectory("$CI_PROJECT_DIR\$EXE_RELEASE_FOLDER\", "$CI_PROJECT_DIR\target\$PACKAGE_NAME-$NEW_VERSION.zip")'   
  artifacts:
    expire_in: 1 week
    paths:
      - build.txt
  dependencies:
    - job1 
  variables:
    NEW_VERSION: ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 GitLab CI 的管道中将变量的值从一个作业传递到下一个作业? - How can I pass value of variable from one job to next job in pipeline in GitLab CI? 在GitLab CI作业中,如何确定正在使用哪个版本的GitLab Runner? - Inside a GitLab CI job, how can I tell which version of GitLab Runner is being used? 在 GitLab CI 中使用来自合并请求作业的工件 - Use artifacts from merge request job in GitLab CI 如何设置带有标签的作业工件永不过期 Gitlab CI - How to set job artifacts with tags to never expire Gitlab CI 如何使用缓存和工件加速 Gitlab CI 作业 - How to speed up Gitlab CI job with cache and artifacts 如何基于不同的跑步者跳过 gitlab-ci.yml 中的工作? - How to skip job in gitlab-ci.yml base on different runner? 如何将值传递给 Gitlab CI 作业 - How to pass values to a Gitlab CI Job Gitlab CI/CD:将作业环境变量传递给 shell 脚本 - Gitlab CI/CD: pass job environment variables to shell script 如何在 GitLab CI 中构建作业名称的 url 以下载最新的工件? - How to construct urls for job names for downloading latest artifacts in GitLab CI? Gitlab CI - 我是否应该为每个作业保留一组要在运行器上重用的工件,而无需在管道上重新下载工件? - Gitlab CI - should I keep a set of artifacts to be reused on a runner, for each job, without re-downloading artifacts on the pipeline?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM