2

I am using the Azure DevOps server pipeline shell script task when I passed the "$(Build.SourcesDirectory)" variable as a shell script arguments, I found the path is not getting "/" while printing the variable.

Here is the Azure DevOps Pipeline Task: enter image description here

Here is my shell script:

!/bin/bash echo $1

Here is the output of the pipeline:

enter image description here

please give some idea how I can get actual path (with "/") while printing the variable?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Dharti Sutariya
  • 419
  • 1
  • 5
  • 14

2 Answers2

1

I found the solution. I have added Azure DevOps Server 2019 predefine variable as extra vars in azure-pipelines.yml like this:

- 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)"'

Then I can access the variable in my playbook using this:

---
- hosts: localhost
  tasks:
  - name: show debug
    debug:
      msg: "Dir {{ build_source_dir }}"
Dharti Sutariya
  • 419
  • 1
  • 5
  • 14
0

If I am not guess wrong, the agent this pipeline is using located in Windows?


Please try with the pass the variable as $BUILD_SOURCESDIRECTORY without any double or single quote(s).

enter image description here

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35