2
votes

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?

2
Use double quotes on the path like "D:\Agent_1...".sungtm
Now getting like this "D:\Agent_1\work\s", missing " \1" in the path.Dharti Sutariya
Update command as sh tfsvariable.sh "$(Build.SourcesDirectory)" in the task configuration and try.sungtm
Updated Command as: sh tfsvariable.sh "$(Build.SourcesDirectory)" Getting Like this: "D:\Agent_1\work^A\s"Dharti Sutariya

2 Answers

1
votes

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 }}"
0
votes

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