在Azure管道作业之间共享文件 [英] Share files between azure pipeline Jobs

查看:102
本文介绍了在Azure管道作业之间共享文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Azure管道的文档中,我读到:

In the documentation of the Azure pipelines, I read that:

每个代理一次只能运行一个作业.在中运行多个作业 并行,您必须配置多个代理.

Each agent can run only one job at a time. To run multiple jobs in parallel you must configure multiple agents.

默认情况下,当您在自托管代理上运行管道时, 子目录在两次连续运行之间被清理.作为一个 结果,您可以进行增量构建和部署,前提是 执行任务以利用这一点.您可以覆盖此 使用作业上的工作区设置的行为.

When you run a pipeline on a self-hosted agent, by default, none of the sub-directories are cleaned in between two consecutive runs. As a result, you can do incremental builds and deployments, provided that tasks are implemented to make use of that. You can override this behavior using the workspace setting on the job.

管道项目提供了一种方法,可以在一个阶段的各个阶段之间共享文件 管道或不同管道之间.它们通常是输出 需要由另一项工作消耗或 部署.

Pipeline artifacts provide a way to share files between stages in a pipeline or between different pipelines. They are typically the output of a build process that needs to be consumed by another job or be deployed.

作为初学者,在阅读本文之后,我有一些疑问:

As a beginner, after reading this, I have some doubts:

  1. 如果我在azure-pipelines.yaml中有2个作业(第二个作业在第一个作业之后运行),那么两个作业都将在同一代理中运行吗?同一管道中的不同作业是否共享可以通过变量Pipeline.Workspace引用的相同工作空间? (很明显,在并行作业运行的情况下,它将需要多个代理.)
  2. 第一项作业一步一步生成了一些文件.是否可以在不使用构件的情况下使用第二个作业中的那些文件(通常使用构件,第一个作业发布构件,第二个作业下载构件)?
  1. If I have 2 jobs (2nd job runs after the 1st) in an azure-pipelines.yaml, will both the jobs run in the same agent? Do different jobs in the same pipeline share the same workspace that can be referenced via the variable Pipeline.Workspace? ( It is clear that in the parallel job run case, it would need multiple agents).
  2. The 1st job generates some files in one step. Is it possible to consume those files in 2nd job without using artifacts (normally using artifacts, 1st job publishes the artifact and 2nd job downloads it)?

有人可以帮我消除这些疑问吗?

Can some please help me to clear these doubts?

推荐答案

如果我有2个作业(第二个作业在第一个作业之后运行), azure-pipelines.yaml,这两个作业将在同一代理中运行吗?

If I have 2 jobs (2nd job runs after the 1st) in an azure-pipelines.yaml, will both the jobs run in the same agent?

严格来说,不,UIYAML都无法实现.

Strictly speaking, NO, neither UI nor YAML can achieve that.

正如您从文档中看到的那样:每个代理一次只能运行一个作业.从理论上讲,我们的设计逻辑是一个作业是独立运行个人,不同职位之间的沟通需要使用中间件",例如variableartifact等.

As what you saw from the document: Each agent can run only one job at a time. Our design logic is, in theory, one job is an independent running individual, the communication between different jobs requires the use of "middleware", like variable, artifact and etc.

在同一管道中执行不同的作业共享相同的工作空间 可以通过变量Pipeline.Workspace引用?

Do different jobs in the same pipeline share the same workspace that can be referenced via the variable Pipeline.Workspace?

样本1:

我在一个管道中有2个作业,一个是job01,另一个是job02.

I have 2 jobs in one pipeline, one is job01 and another is job02.

job01中,我将一个json文件创建为$(Pipeline.Workspace)名称project.json:

In job01, I create one json file into $(Pipeline.Workspace) names project.json:

在job02中,打印路径$(Pipeline.Workspace)下的文件列表:

In job02, print the files list that under path $(Pipeline.Workspace):

您可以看到,第二个作业无法访问第一个作业的输出目录.

You can see, the second job could not access the output directory of first job.

BUT ,有一种特殊情况,即管道正在使用自代理池运行,并且该池中仅存在一个代理.

BUT, there has one special case, that the pipeline is running with self-agent pool and only one agent exists in that pool.

此时,由于池中只有一个代理,它们可以在同一代理上运行.而且,如果您没有在作业定义中手动执行clean操作,则在这种特殊情况下,文件可以在作业之间共享,因为它们使用的是恒定的本地路径.

At this time, they can run on same agent since there is only one agent in the pool. And, if you do not manually perform clean operation in the job definition, files can be shared between jobs in this special scenario because they are using a constant local path.

示例2:

与先前的示例相同,但是这次将运行池更改为仅包含1个代理的池.

第一个作业一步一步生成了一些文件.是否有可能 在不使用工件的情况下将其用于第二项工作中

The 1st job generates some files in one step. Is it possible to consume those files in 2nd job without using artifacts

我认为我上面的特殊情况描述和sample2已经回答了这个问题.

I think my above special case description and sample2 has answer this.

是的,有可能.您可以参考以实现此需求.但是,大多数情况下,我们建议您使用工件在作业之间传递文件.

Yes, it possible. You can refer to that to achieve this demand. But, mostly we recommend you use artifacts to pass files between jobs.

这篇关于在Azure管道作业之间共享文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆