powershell - 如何在我的 Ansible Playbook 中使用 Azure DevOps 服务器 (TFS) 预定义变量?

标签 powershell shell ansible ansible-role azure-devops-server-2019

我想在我的剧本中使用 Azure DevOps 预定义变量“ $(Build.SourcesDirectory) ”:

这是我的剧本:

---
- hosts: KBR_MTL361
  tasks:
   - name: copy file
     win_copy:
      src: D:\Web.config
      dest: $(Build.SourcesDirectory)

我正在使用 Azure DevOps Pipeline 运行这个 ansible-playbook:

TFS Pipeline Task

但它不起作用

有没有人知道如何在管道中使用变量?

最佳答案

只需在 中添加您的变量作为附加参数azure-pipelines.yml 像这样:

    - task: Ansible@0
      inputs:
        ansibleInterface: 'agentMachine'
        playbookPathOnAgentMachine: 'ansible/tfs_playbooks/install_agent.yml'
        inventoriesAgentMachine: 'file'
        inventoryFileOnAgentMachine: 'hosts.yml'
        args: '--extra-vars "build_source_dir=$(Build.SourcesDirectory) AGENT_URL=$(AGENT_URL)"'

然后你可以访问你的 中的变量剧本 :
---
- hosts: localhost
  tasks:
  - name: show debug
    debug:
      msg: "Dir {{ build_source_dir }} agent url {{AGENT_URL}}"

关于powershell - 如何在我的 Ansible Playbook 中使用 Azure DevOps 服务器 (TFS) 预定义变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59768155/

相关文章:

ansible - `ansible` 临时命令通过管道传送到 `jq`

ssh - ansible 剧本 [设置] 收集事实 - SSH UNREACHABLE 连接在横幅期间超时

Ansible - 如何使用循环设置 var

Python - 获取命令输出无法解码

powershell - 在Powershell中组合多个Get-Content cmdlet

shell - 如何通过 shell 获取 InfluxDB 版本

mysql - 在shell脚本中执行MySQL命令?

json - 从JSON提取值

powershell - 如何更改 IPython shell 文本文字颜色 (Windows Powershell)

shell - Bamboo - 在任务/脚本之间传递环境变量