Dharti Sutariya
Dharti Sutariya

Reputation: 489

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?

Upvotes: 2

Views: 1367

Answers (2)

Dharti Sutariya
Dharti Sutariya

Reputation: 489

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

Upvotes: 1

Mengdi Liang
Mengdi Liang

Reputation: 19016

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

Upvotes: 0

Related Questions