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

When passing a variable to build.cake that contains a space, the script throws an error #103

Open
2 tasks done
nick5454 opened this issue May 5, 2021 · 4 comments
Open
2 tasks done
Labels

Comments

@nick5454
Copy link

nick5454 commented May 5, 2021

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake Frosting

Cake version

1.1.0

Operating system

macOS

Operating system architecture

64-Bit

CI Server

Azure Devops

What are you seeing?

When passing variable with a space, the logic parses the space and causes an error. "Any CPU" becomes Platform=Any CPU=???

What is expected?

variable: Platform = "Any CPU" should be passed as "Any CPU" to build.cake. This could be a powershell issue, but I believe it's a cake parsing issue.

Steps to Reproduce

Using the yml below, notice Platform has a space and when calling build.cake the parsing fails

yml:

  - master
  - development
  - dev
  - release/*
  - hotfix/*

pr:
  - master
  - development
  - release/*

variables:
  SYSTEM_ACCESSTOKEN: $(System.AccessToken)
  SolutionFile: "MyApp.sln"
  ZipProjects: "MyApp.iOS="
  StartUpProject: ""
  DomainProject: ""
  DomainOutputSql: ""
  DbContext: ""  
  BranchProject: "MyApp"
  Platform: "Any CPU"

pool:
  vmImage: 'macOS-latest'

stages:
- stage: BuildApp
  jobs:
  - job: myjob
    steps:
      - task: PowerShell@2
        displayName: 'PowerShell Script'
        inputs:
          targetType: filePath
          filePath: 'build/build_cake.ps1'
          arguments: '--Target=Deploy --Configuration=Store --Platform "$(Platform)" --ZipProjects "$(ZipProjects)" --SolutionFilePath "$(SolutionFile)" --StartUpProject "$(StartUpProject)" --DomainProject "$(DomainProject)" --DomainOutputSql "$(DomainOutputSql)" --DbContext "$(DbContext)" --BranchProject "$(BranchProject)"'
        env:
          SYSTEM_ACCESSTOKEN: $(System.AccessToken)
          NUGET_AUTH_TOKEN: $(NUGET_AUTH_TOKEN)```

### Output log

2021-05-05T16:45:12.7838560Z ##[debug]Evaluating condition for step: 'PowerShell Script'
2021-05-05T16:45:12.7840480Z ##[debug]Evaluating: SucceededNode()
2021-05-05T16:45:12.7841120Z ##[debug]Evaluating SucceededNode:
2021-05-05T16:45:12.7842160Z ##[debug]=> True
2021-05-05T16:45:12.7843380Z ##[debug]Result: True
2021-05-05T16:45:12.7844860Z ##[section]Starting: PowerShell Script
2021-05-05T16:45:12.7855390Z ==============================================================================
2021-05-05T16:45:12.7855770Z Task         : PowerShell
2021-05-05T16:45:12.7856610Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2021-05-05T16:45:12.7857190Z Version      : 2.180.1
2021-05-05T16:45:12.7857510Z Author       : Microsoft Corporation
2021-05-05T16:45:12.7857900Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2021-05-05T16:45:12.7858330Z ==============================================================================
2021-05-05T16:45:13.0075560Z ##[debug]Using node path: /Users/runner/runners/2.185.1/externals/node10/bin/node
2021-05-05T16:45:13.7711220Z ##[debug]agent.TempDirectory=/Users/runner/work/_temp
2021-05-05T16:45:13.7737530Z ##[debug]loading inputs and endpoints
2021-05-05T16:45:13.7747290Z ##[debug]loading INPUT_TARGETTYPE
2021-05-05T16:45:13.7769460Z ##[debug]loading INPUT_FILEPATH
2021-05-05T16:45:13.7772360Z ##[debug]loading INPUT_ARGUMENTS
2021-05-05T16:45:13.7774370Z ##[debug]loading INPUT_SCRIPT
2021-05-05T16:45:13.7776280Z ##[debug]loading INPUT_ERRORACTIONPREFERENCE
2021-05-05T16:45:13.7778210Z ##[debug]loading INPUT_FAILONSTDERR
2021-05-05T16:45:13.7780070Z ##[debug]loading INPUT_SHOWWARNINGS
2021-05-05T16:45:13.7781580Z ##[debug]loading INPUT_IGNORELASTEXITCODE
2021-05-05T16:45:13.7783370Z ##[debug]loading INPUT_PWSH
2021-05-05T16:45:13.7785320Z ##[debug]loading INPUT_WORKINGDIRECTORY
2021-05-05T16:45:13.7787180Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
2021-05-05T16:45:13.7789040Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
2021-05-05T16:45:13.7790570Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
2021-05-05T16:45:13.7796270Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
2021-05-05T16:45:13.7799550Z ##[debug]loading SECRET_NUGET_AUTH_TOKEN
2021-05-05T16:45:13.7801550Z ##[debug]loaded 15
2021-05-05T16:45:13.7807130Z ##[debug]Agent.ProxyUrl=undefined
2021-05-05T16:45:13.7808720Z ##[debug]Agent.CAInfo=undefined
2021-05-05T16:45:13.7809500Z ##[debug]Agent.ClientCert=undefined
2021-05-05T16:45:13.7810180Z ##[debug]Agent.SkipCertValidation=undefined
2021-05-05T16:45:13.7822070Z ##[debug]check path : /Users/runner/work/_tasks/PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1/2.180.1/task.json
2021-05-05T16:45:13.7826410Z ##[debug]adding resource file: /Users/runner/work/_tasks/PowerShell_e213ff0f-5d5c-4791-802d-52ea3e7be1f1/2.180.1/task.json
2021-05-05T16:45:13.7827630Z ##[debug]system.culture=en-US
2021-05-05T16:45:13.7851230Z ##[debug]errorActionPreference=stop
2021-05-05T16:45:13.7854390Z ##[debug]showWarnings=false
2021-05-05T16:45:13.7855820Z ##[debug]failOnStderr=false
2021-05-05T16:45:13.7857370Z ##[debug]ignoreLASTEXITCODE=false
2021-05-05T16:45:13.7859660Z ##[debug]workingDirectory=/Users/runner/work/1/s
2021-05-05T16:45:13.7860450Z ##[debug]check path : /Users/runner/work/1/s
2021-05-05T16:45:13.7862020Z ##[debug]targetType=filePath
2021-05-05T16:45:13.7863480Z ##[debug]filePath=/Users/runner/work/1/s/build/build_cake.ps1
2021-05-05T16:45:13.7868930Z ##[debug]arguments=--Target=Deploy --Configuration=Store --Platform "Any CPU" --ZipProjects "iPartner.iOS=" --SolutionFilePath "MyApp.sln" --StartUpProject "" --DomainProject "" --DomainOutputSql "" --DbContext "" --BranchProject "MyApp"
2021-05-05T16:45:13.7882470Z Generating script.
2021-05-05T16:45:13.7917350Z ##[debug]Processed: ##vso[task.logdetail id=1f487e06-e8ff-40ad-99c8-485cbcbe2e14;type=command;name=command;]Formatted command: . '/Users/runner/work/1/s/build/build_cake.ps1' --Target=Deploy --Configuration=Store --Platform "Any CPU" --ZipProjects "MyApp.iOS=" --SolutionFilePath "MyApp.sln" --StartUpProject "" --DomainProject "" --DomainOutputSql "" --DbContext "" --BranchProject "MyApp"
2021-05-05T16:45:13.7919620Z ##[debug]Agent.Version=2.185.1
2021-05-05T16:45:13.7920360Z ##[debug]agent.tempDirectory=/Users/runner/work/_temp
2021-05-05T16:45:13.7921510Z ##[debug]check path : /Users/runner/work/_temp
2021-05-05T16:45:13.7922110Z ========================== Starting Command Output ===========================
2021-05-05T16:45:13.7923110Z ##[debug]which 'pwsh'
2021-05-05T16:45:13.7924080Z ##[debug]found: '/usr/local/bin/pwsh'
2021-05-05T16:45:13.7925050Z ##[debug]which '/usr/local/bin/pwsh'
2021-05-05T16:45:13.7925950Z ##[debug]found: '/usr/local/bin/pwsh'
2021-05-05T16:45:13.7926920Z ##[debug]/usr/local/bin/pwsh arg: -NoLogo
2021-05-05T16:45:13.7927910Z ##[debug]/usr/local/bin/pwsh arg: -NoProfile
2021-05-05T16:45:13.7928900Z ##[debug]/usr/local/bin/pwsh arg: -NonInteractive
2021-05-05T16:45:13.7929830Z ##[debug]/usr/local/bin/pwsh arg: -Command
2021-05-05T16:45:13.7930940Z ##[debug]/usr/local/bin/pwsh arg: . '/Users/runner/work/_temp/83b58027-96e2-405d-a94e-f18f12fa0d46.ps1'
2021-05-05T16:45:13.7931840Z ##[debug]exec tool: /usr/local/bin/pwsh
2021-05-05T16:45:13.7932520Z ##[debug]arguments:
2021-05-05T16:45:13.7933390Z ##[debug]   -NoLogo
2021-05-05T16:45:13.7934240Z ##[debug]   -NoProfile
2021-05-05T16:45:13.7935150Z ##[debug]   -NonInteractive
2021-05-05T16:45:13.7936040Z ##[debug]   -Command
2021-05-05T16:45:13.7937040Z ##[debug]   . '/Users/runner/work/_temp/83b58027-96e2-405d-a94e-f18f12fa0d46.ps1'
2021-05-05T16:45:13.7938270Z [command]/usr/local/bin/pwsh -NoLogo -NoProfile -NonInteractive -Command . '/Users/runner/work/_temp/83b58027-96e2-405d-a94e-f18f12fa0d46.ps1'
2021-05-05T16:45:15.3878690Z Preparing to run build script...
2021-05-05T16:45:15.4604020Z Tools: /Users/runner/work/1/s/build/tools
2021-05-05T16:45:15.4611460Z Tools: /Users/runner/work/1/s/build/tools/Addins
2021-05-05T16:45:21.8034060Z Start testing Cake path.
2021-05-05T16:45:21.8085380Z Running build script...
2021-05-05T16:45:22.7154760Z 
2021-05-05T16:45:22.7158560Z Error: Unknown command 'CPU'.
2021-05-05T16:45:22.7159770Z 
2021-05-05T16:45:22.7161940Z        .\build\build.cake --verbosity=Diagnostic --Target=Deploy 
2021-05-05T16:45:22.7164770Z --Configuration=Store --Platform Any CPU --ZipProjects MyApp.iOS= 
2021-05-05T16:45:22.7167780Z --SolutionFilePath MyApp.sln --StartUpProject --DomainProject 
2021-05-05T16:45:22.7169780Z --DomainOutputSql --DbContext --BranchProject MyApp
2021-05-05T16:45:22.7171170Z                                                                                 
2021-05-05T16:45:22.7172480Z ^^^ No such command
2021-05-05T16:45:22.7173260Z 
2021-05-05T16:45:22.7234780Z ##[debug]$LASTEXITCODE: 255
2021-05-05T16:45:22.7476860Z ##[debug]Exit code 1 received from tool '/usr/local/bin/pwsh'
2021-05-05T16:45:22.7482740Z ##[debug]STDIO streams have closed for tool '/usr/local/bin/pwsh'
2021-05-05T16:45:22.7497960Z ##[debug]task result: Failed
2021-05-05T16:45:22.7530120Z ##[error]PowerShell exited with code '1'.
2021-05-05T16:45:22.7542400Z ##[debug]Processed: ##vso[task.issue type=error;]PowerShell exited with code '1'.
2021-05-05T16:45:22.7553090Z ##[debug]Processed: ##vso[task.complete result=Failed;]PowerShell exited with code '1'.
2021-05-05T16:45:22.7564290Z ##[section]Finishing: PowerShell Script
@nick5454 nick5454 changed the title When including a variable with a space in it the cake fails When passing a variable to build.cake that contains a space, the script throws an error May 5, 2021
@augustoproiete
Copy link
Member

@nick5454 What is the content of build/build_cake.ps1? This is the script that is ultimately executing Cake and not adding the required quotes.

@nick5454
Copy link
Author

nick5454 commented May 5, 2021

@nick5454 What is the content of build/build_cake.ps1? This is the script that is ultimately executing Cake and not adding the required quotes.

build_cake.ps1.txt

@nick5454
Copy link
Author

nick5454 commented May 5, 2021

@augustoproiete I assume I could escape it inside the ps1 file at the end where cakeArguments are

For the work around I pass in Any__CPU and added a platform.Replace("__", " ") which works

@augustoproiete
Copy link
Member

@nick5454 Great. I'm moving this issue to the resources repo as the fix would be in the bootstrapper template for .NET Framework and not in Cake itself.

N.B.: Our recommendation is to migrate your builds to use the .NET Tool for running Cake if possible. This issue would not happen with the .NET tool because the new bootstrappers handle quotes correctly.

@augustoproiete augustoproiete transferred this issue from cake-build/cake May 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants