Search code examples
linuxshellazure-pipelinesazure-devops-server-2019

When I pass the variable(path) in azure devops server shell script task, path prints without "/"


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?


Solution

  • 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 }}"