任务在执行上下文中运行,该上下文是代理主机或容器。
引用此定义的定义:steps.task、steps.script、steps.powershell、steps.pwsh、steps.bash、steps.checkout, steps.download, steps.downloadBuild, steps.getPackage, steps.publish, steps.reviewApp
实现
执行 | 说明 |
---|---|
目标:字符串 | 运行此步骤或任务的环境。 |
目标:容器、命令、settableVariables | 使用环境配置步骤目标,以及允许的命令和变量列表。 |
注解
单个步骤可以通过指定 target
来替代其上下文,还可以选择配置容器、命令和可设置变量。
target: string
按名称指定步骤目标。
target: string # Environment in which to run this step or task.
target
字符串。
可用选项是 host
以代理主机为目标以及管道中定义的任何容器。
目标:容器、命令、settableVariables
使用容器名称、命令和可设置变量配置步骤目标。
target:
container: string # Container to target (or 'host' for host machine).
commands: any | restricted # Set of allowed logging commands ('any' or 'restricted').
settableVariables: none | [ string ] # Restrictions on which variables that can be set.
性能
container
字符串。
容器以主机为目标(或“主机”)。
commands
字符串。
允许的日志记录命令集(“any”或“restricted”)。 any |限制。
settableVariables
target.settableVariables。
可设置的变量的限制。
目标:容器、命令
使用环境和允许的命令列表配置步骤目标。
target:
container: string # Container to target (or 'host' for host machine).
commands: any | restricted # Set of allowed logging commands ('any' or 'restricted').
性能
container
字符串。
容器以主机为目标(或“主机”)。
commands
字符串。
允许的日志记录命令集(“any”或“restricted”)。 any |限制。
注解
配置步骤目标时,无需配置所有这些属性。 如果未指定,则 container
的默认值为 host
,commands
的默认值为 any
,settableVariables
的默认值允许按步骤设置所有变量。
步骤定位和命令隔离
Azure Pipelines 支持在容器或代理主机上运行作业。 以前,整个作业设置为这两个目标之一。 现在,各个步骤(任务或脚本)可以在所选的目标上运行。 步骤也可能面向其他容器,因此管道可以在专用的专用容器中运行每个步骤。
注释
此功能目前为公共预览版。 如果你对此功能有任何反馈或疑问,请在 开发人员社区中告知我们。
容器可以充当隔离边界,防止代码在主机上进行意外更改。
与代理 中的服务通信和访问服务的方式不受容器中的隔离步骤的影响。 因此,我们还引入了可用于步骤目标的命令限制模式。 将 commands
设置为 restricted
将限制一个步骤可从代理请求的服务。 它将不再能够附加日志、上传项目和其他某些作。
例子
以下示例演示了在作业容器中的主机和另一个容器中运行步骤。
resources:
containers:
- container: python
image: python:3.8
- container: node
image: node:13.2
jobs:
- job: example
container: python
steps:
- script: echo Running in the job container
- script: echo Running on the host
target: host
- script: echo Running in another container, in restricted commands mode
target:
container: node
commands: restricted