我想将多个作业生成的文件下载到 azure 管道上的一个文件夹中。 这是我想要完成的架构:
{resultsArr && <ResultsList resultsArr={resultsArr} resultsType={resultsType}/>}
其中目录 jobs:
- job: job1
pool: {vmImage: 'Ubuntu-16.04'}
steps:
- bash: |
printf "Hello form job1\n" > $(Pipeline.Workspace)/file.1
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Pipeline.Workspace)/file.1
- job: job2
pool: {vmImage: 'Ubuntu-16.04'}
steps:
- bash: |
printf "Hello form job2\n" > $(Pipeline.Workspace)/file.2
- task: PublishPipelineArtifact@1
inputs:
targetPath: $(Pipeline.Workspace)/file.2
- job: check_prev_jobs
dependsOn: "all other jobs"
pool: {vmImage: 'Ubuntu-16.04'}
steps:
- bash: |
mkdir -p $(Pipeline.Workspace)/previous_artifacts
- task: DownloadPipelineArtifact@2
inputs:
source: current
path: $(Pipeline.Workspace)/previous_artifacts
仅包含 $(Pipeline.Workspace)/previous_artifacts
和 file.1
,没有目录 file.2
和 job1
包含 job2
和 {{ 1}} 分别。
谢谢!
使用 /file.1
答案。我创建了以下 /file.2
文件:
@Yujun Ding-MSFT's
但是,如下面的屏幕截图所示,我仍然在单独的作业相关目录中获取每个 azure-pipelines.yml
文件:
不幸的是,在我看来,使用 Pipeline.Artifacts 可能无法实现我想要的,如 this Microsoft discussion 中所述。鉴于 Build.Artifacts 在这一点上已被弃用,这将是一个遗憾。
答案 0 :(得分:2)
在您当前的情况下,我们建议您将关键字:artifactName 添加到您的 publishArtifact 任务中。我修改了你的脚本并在我这边测试。希望对您有所帮助:
trigger: none
# pool:
# vmImage: ubuntu-latest
jobs:
- job: Job_1
displayName: job 1
pool:
vmImage: ubuntu-20.04
steps:
- checkout: self
persistCredentials: True
- task: Bash@3
displayName: Bash Script
inputs:
targetType: inline
script: 'printf "Hello form job1\n" > $(Pipeline.Workspace)/file.1 '
- task: PublishPipelineArtifact@1
displayName: Publish Pipeline Artifact
inputs:
path: $(Pipeline.Workspace)/file.1
artifactName: job1
- job: Job_2
displayName: job2
pool:
vmImage: ubuntu-20.04
steps:
- checkout: self
- task: Bash@3
displayName: Bash Script copy
inputs:
targetType: inline
script: 'printf "Hello form job1\n" > $(Pipeline.Workspace)/file.2 '
- task: PublishPipelineArtifact@1
displayName: Publish Pipeline Artifact copy
inputs:
path: $(Pipeline.Workspace)/file.2
artifactName: job2
- job: Job_3
displayName: Agent job
dependsOn:
- Job_1
- Job_2
pool:
vmImage: ubuntu-20.04
steps:
- checkout: self
- task: Bash@3
displayName: Bash Script
inputs:
targetType: inline
script: ' mkdir -p $(Pipeline.Workspace)/previous_artifacts'
- task: DownloadPipelineArtifact@2
displayName: Download Pipeline Artifact
inputs:
path: '$(Pipeline.Workspace)/previous_artifacts '
更新: 因为作业在不同的会话中运行。所以我们不能只是复制文件或使用发布工件来帮助我们合并两个作业工件。我修改了您的 yaml 文件,这可能对您有所帮助:
stages:
- stage: generate
jobs:
- job: Job_1
displayName: job1
pool:
vmImage: ubuntu-20.04
variables:
JOB_NAME: $(Agent.JobName)
DIR: $(Pipeline.Workspace)/$(JOB_NAME)
steps:
- checkout: self
- bash: |
mkdir -p $DIR
cd $DIR
printf "Time form job1\n" > $JOB_NAME.time
printf "Hash form job1\n" > $JOB_NAME.hash
printf "Raw form job1\n" > $JOB_NAME.raw
printf "Nonesense form job1\n" > $JOB_NAME.nonesense
displayName: Generate files
- task: PublishPipelineArtifact@1
displayName: Publish Pipeline Artifact
inputs:
path: $(DIR)
artifactName: job1
- job: Job_2
displayName: job2
dependsOn:
- Job_1
pool:
vmImage: ubuntu-20.04
variables:
JOB_NAME: $(Agent.JobName)
DIR: $(Pipeline.Workspace)/$(JOB_NAME)
steps:
- checkout: self
- bash: |
mkdir -p $DIR
cd $DIR
printf "Time form job2\n" > $JOB_NAME.time
printf "Hash form job2\n" > $JOB_NAME.hash
printf "Raw form job2\n" > $JOB_NAME.raw
printf "Nonesense form job2\n" > $JOB_NAME.nonesense
displayName: Generate files
- task: DownloadPipelineArtifact@2
displayName: Download Pipeline Artifact
inputs:
buildType: 'current'
artifactName: 'job1'
targetPath: '$(DIR)'
- task: PublishPipelineArtifact@1
displayName: Publish Pipeline Artifact copy
inputs:
path: $(DIR)
artifactName: job2
- stage: analyze
jobs:
- job: download_display
displayName: Download and display
pool:
vmImage: ubuntu-20.04
variables:
DIR: $(Pipeline.Workspace)/artifacts
steps:
- checkout: self
- bash: |
mkdir -p $DIR
- task: DownloadPipelineArtifact@2
displayName: Download Pipeline Artifact
inputs:
buildType: 'current'
artifactName: 'job2'
itemPattern: '**/*.time'
targetPath: '$(DIR)'
- bash: |
ls -lR $DIR
cd $DIR
cd $(System.ArtifactsDirectory)
displayName: Check dir content