【问题标题】:When I pass the variable(path) in azure devops server shell script task, path prints without "/"当我在 azure devops 服务器 shell 脚本任务中传递变量(路径)时,路径打印不带“/”
【发布时间】:2020-05-10 09:39:31
【问题描述】:

我正在使用 Azure DevOps 服务器管道 shell 脚本任务,当我将“$(Build.SourcesDirectory)”变量作为 shell 脚本参数传递时,我发现在打印变量时路径没有得到“/”。

这是 Azure DevOps Pipeline 任务:

这是我的 shell 脚本:

!/bin/bash 回声 $1

这是管道的输出:

请告诉我如何在打印变量时获取实际路径(使用“/”)?

【问题讨论】:

  • 在路径上使用双引号,例如"D:\Agent_1..."
  • 现在变成这样“D:\Agent_1\work\s”,路径中缺少“\1”。
  • 在任务配置中将命令更新为sh tfsvariable.sh "$(Build.SourcesDirectory)"并尝试。
  • 将命令更新为:sh tfsvariable.sh "$(Build.SourcesDirectory)" 如下:"D:\Agent_1\work^A\s"

标签: linux shell azure-pipelines azure-devops-server-2019


【解决方案1】:

我找到了解决方案。 我已将 Azure DevOps Server 2019 预定义变量添加为 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)"'

然后我可以使用以下方法访问我的剧本中的变量:

---
- hosts: localhost
  tasks:
  - name: show debug
    debug:
      msg: "Dir {{ build_source_dir }}"

【讨论】:

    【解决方案2】:

    如果我没猜错,这个管道使用的代理位于 Windows 中?


    请尝试将变量作为$BUILD_SOURCESDIRECTORY 传递,不带任何双引号或单引号。

    【讨论】:

    • 嘿,@Merlin 我已经应用了 $BUILD_SOURCESDIRECTORY 变量。这次输出为空白“”,什么都看不到。
    • @DhartiSutariya,你代理的系统是windows吗?
    • 是的,Agent 正在 windows 上运行,并在 Azure DevOps Server 2019 中添加了一个 Linux 服务器的 SSH 服务连接
    猜你喜欢
    • 2012-04-22
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 2021-01-20
    • 2011-08-16
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    相关资源
    最近更新 更多