Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad substitution error on yaml template expansion #1647

Closed
philippslang opened this issue Jun 27, 2018 · 14 comments
Closed

Bad substitution error on yaml template expansion #1647

philippslang opened this issue Jun 27, 2018 · 14 comments

Comments

@philippslang
Copy link

Have you tried trouble shooting?

yes

Agent Version and Platform

2.134.2, CentOS 7

VSTS Type and Version

VisualStudio.com

What's not working?

I have a yaml definition

trigger: none

phases:
  - phase: Test
    queue:
      name: ResSimTesting
      demands:
        - Agent.OS -equals Linux

    steps:
    - template: ../bugs/bad-substitution-template.vsts-ci.yaml
      parameters:
        param: some

referencing this template

parameters:
  param: default

steps:
- task: Bash@3
  displayName: bash expansion
  inputs:
    targetType: 'inline'
    script: |
      echo ${{ parameters.param }}

erroring with bad substitution of the variable

2018-06-27T07:37:36.2539801Z ##[debug]Evaluating condition for step: 'bash expansion'
2018-06-27T07:37:36.2560862Z ##[debug]Evaluating: succeeded()
2018-06-27T07:37:36.2580270Z ##[debug]Evaluating succeeded:
2018-06-27T07:37:36.2603629Z ##[debug]=> True
2018-06-27T07:37:36.2622652Z ##[debug]Result: True
2018-06-27T07:37:36.2636868Z ##[section]Starting: bash expansion
2018-06-27T07:37:36.2841313Z ==============================================================================
2018-06-27T07:37:36.2851100Z Task         : Bash
2018-06-27T07:37:36.2860544Z Description  : Run a Bash script on macOS, Linux, or Windows
2018-06-27T07:37:36.2869997Z Version      : 3.136.0
2018-06-27T07:37:36.2879457Z Author       : Microsoft Corporation
2018-06-27T07:37:36.2888936Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613738)
2018-06-27T07:37:36.2898625Z ==============================================================================
2018-06-27T07:37:36.5117712Z ##[debug]agent.workFolder=/datadrive/vsts/work
2018-06-27T07:37:36.5168284Z ##[debug]loading inputs and endpoints
2018-06-27T07:37:36.5183651Z ##[debug]loading INPUT_TARGETTYPE
2018-06-27T07:37:36.5198215Z ##[debug]loading INPUT_FILEPATH
2018-06-27T07:37:36.5213384Z ##[debug]loading INPUT_SCRIPT
2018-06-27T07:37:36.5228169Z ##[debug]loading INPUT_WORKINGDIRECTORY
2018-06-27T07:37:36.5243367Z ##[debug]loading INPUT_FAILONSTDERR
2018-06-27T07:37:36.5257878Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2018-06-27T07:37:36.5274726Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2018-06-27T07:37:36.5289755Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2018-06-27T07:37:36.5305238Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2018-06-27T07:37:36.5320108Z ##[debug]loaded 9
2018-06-27T07:37:36.5335927Z ##[debug]check path : /datadrive/vsts/work/_tasks/Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b/3.136.0/task.json
2018-06-27T07:37:36.5351237Z ##[debug]set resource file to: /datadrive/vsts/work/_tasks/Bash_6c731c3c-3c68-459a-a5c9-bde6e6595b5b/3.136.0/task.json
2018-06-27T07:37:36.5366800Z ##[debug]system.culture=en-US
2018-06-27T07:37:36.5381024Z ##[debug]failOnStderr=false
2018-06-27T07:37:36.5396315Z ##[debug]workingDirectory=/datadrive/vsts/work/9/s
2018-06-27T07:37:36.5410647Z ##[debug]check path : /datadrive/vsts/work/9/s
2018-06-27T07:37:36.5425896Z ##[debug]targetType=inline
2018-06-27T07:37:36.5440517Z ##[debug]script=echo ${{ parameters.param }}
2018-06-27T07:37:36.5450494Z Generating script.
2018-06-27T07:37:36.5465758Z ##[debug]which 'bash'
2018-06-27T07:37:36.5480177Z ##[debug]found: '/usr/bin/bash'
2018-06-27T07:37:36.5495347Z ##[debug]which 'bash'
2018-06-27T07:37:36.5509896Z ##[debug]found: '/usr/bin/bash'
2018-06-27T07:37:36.5519629Z Script contents:
2018-06-27T07:37:36.5529287Z echo ${{ parameters.param }}
2018-06-27T07:37:36.5543828Z ##[debug]Agent.Version=2.134.2
2018-06-27T07:37:36.5558306Z ##[debug]agent.tempDirectory=/datadrive/vsts/work/_temp
2018-06-27T07:37:36.5573374Z ##[debug]check path : /datadrive/vsts/work/_temp
2018-06-27T07:37:36.5588119Z ##[debug]which '/usr/bin/bash'
2018-06-27T07:37:36.5603981Z ##[debug]found: '/usr/bin/bash'
2018-06-27T07:37:36.5618262Z ##[debug]which '/usr/bin/bash'
2018-06-27T07:37:36.5633065Z ##[debug]found: '/usr/bin/bash'
2018-06-27T07:37:36.5648370Z ##[debug]/usr/bin/bash arg: --noprofile
2018-06-27T07:37:36.5663547Z ##[debug]/usr/bin/bash arg: --norc
2018-06-27T07:37:36.5678099Z ##[debug]/usr/bin/bash arg: /datadrive/vsts/work/_temp/fe6001d3-f712-443b-a7e2-c3de090b1129.sh
2018-06-27T07:37:36.5693021Z ##[debug]exec tool: /usr/bin/bash
2018-06-27T07:37:36.5707569Z ##[debug]arguments:
2018-06-27T07:37:36.5722388Z ##[debug]   --noprofile
2018-06-27T07:37:36.5737138Z ##[debug]   --norc
2018-06-27T07:37:36.5752031Z ##[debug]   /datadrive/vsts/work/_temp/fe6001d3-f712-443b-a7e2-c3de090b1129.sh
2018-06-27T07:37:36.5762285Z [command]/usr/bin/bash --noprofile --norc /datadrive/vsts/work/_temp/fe6001d3-f712-443b-a7e2-c3de090b1129.sh
2018-06-27T07:37:36.5772519Z /datadrive/vsts/work/_temp/fe6001d3-f712-443b-a7e2-c3de090b1129.sh: line 1: ${{ parameters.param }}: bad substitution
2018-06-27T07:37:36.5787451Z ##[debug]rc:1
2018-06-27T07:37:36.5802193Z ##[debug]success:true
2018-06-27T07:37:36.5816731Z ##[debug]task result: Failed
2018-06-27T07:37:36.5885411Z ##[error]Bash exited with code '1'.
2018-06-27T07:37:36.5908420Z ##[debug]Processed: ##vso[task.issue type=error;]Bash exited with code '1'.
2018-06-27T07:37:36.5939889Z ##[debug]Processed: ##vso[task.complete result=Failed;]Bash exited with code '1'.
2018-06-27T07:37:36.5963622Z ##[section]Finishing: bash expansion

Did I miss anything?

@TingluoHuang
Copy link
Contributor

@ericsciple looks like template parameters is not get expanded?

@ericsciple
Copy link
Contributor

try this:

parameters:
  param: default

steps:
- task: Bash@3
  displayName: bash expansion
  inputs:
    targetType: 'inline'
    script: |
      ${{ format('echo {0}', parameters.param) }}

or this:

parameters:
  param: default

steps:
- task: Bash@3
  displayName: bash expansion
  inputs:
    targetType: 'inline'
    script: |
      echo $param
  environment:
    param: ${{ parameters.param }}

the first example may not work yet, depending on which scale unit your account is located in.

currently the template expressions must be the whole value.

@philippslang
Copy link
Author

philippslang commented Jun 29, 2018

no 2 did the trick, it just needs to say env instead of environment
Thanks - as always any updates on this in the sprint blog are much appreciated

@4c74356b41
Copy link

4c74356b41 commented Jul 9, 2018

@ericsciple ok, am i being thick again or this doesnt work? how is this supposed to work?

parameters:
  appFolder: ''
  appName: ''
...
  - task: DotNetCoreCLI@2
    displayName: dotnet publish
    inputs:
      command: publish
      projects: src/${{ parameters.appFolder }}/${{ parameters.appName }}/${{ parameters.appName }}.csproj
      arguments: "-c release -o output"

image

i tried with or without quotes (single\double)

@TingluoHuang
Copy link
Contributor

@4c74356b41

projects: ${{ parameters.oneparameter }}

@4c74356b41
Copy link

what is that supposed to mean? @TingluoHuang

@TingluoHuang
Copy link
Contributor

the right side of projects: needs to be one parameter instead of a combination of multiple parameter.

@4c74356b41
Copy link

4c74356b41 commented Jul 9, 2018

ok, this makes no sense, how am I supposed to reuse parameters when i cant combine them? @TingluoHuang

@TingluoHuang
Copy link
Contributor

${{ format('src/{0}/{1}/{2}.csproj', parameters.appFolder, parameters.appName, parameters.appName) }}

@4c74356b41
Copy link

4c74356b41 commented Jul 9, 2018

am i supposed to do this in every case when i need to build a string? how do I combine this with native variables? $(varName)? and the most important question. why do docs not mention this even once?

@TingluoHuang
Copy link
Contributor

@ericsciple for idea.

@ericsciple
Copy link
Contributor

@4c74356b41 currently you will need to use the format function everywhere you need to string concat. We want to enable using template expressions within strings, without requiring the format function, but it's feature work and it just hasn't been the next priority yet. I do think it would be a nice improvement.

The format function is new. I think it has rolled out to every scale unit now.

The docs are behind. I have been working through restructuring the docs based on common friction customers are having. Template docs are next on my list.

@4c74356b41
Copy link

ok, it appears the format function did the trick + it didnt mangle the $(varName) thing and that worked. at least we got that going.

@ericsciple I understand this is a preview feature, but man, when you try something thats supposed to work and it doesn't. Thats reaaaally frustrating (especially when you put 20 hours into that). Maybe I'm not good enough with VSTS.

I really suggest you mention this use exactly one parameter of format() function thing somewhere in the docs. :)

sondreb added a commit to CityChainFoundation/city-chain that referenced this issue Aug 10, 2018
@sondreb
Copy link

sondreb commented Aug 10, 2018

Did not intend to link to a commit, but to follow up for anyone else who are working with YAML and VSTS, here is the proper way of combining parameters in YAML with variables in VSTS:

archiveFile: ${{ format('$(Build.ArtifactStagingDirectory)/$(App.BuildNumber)-{0}-{1}-{2}.zip', parameters.configuration, parameters.platform, parameters.arch) }}

So basically just leave the VSTS variables as a result of the string, and run the format method and supply the parameters with YAML variables/parameters that you have available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants