jenkinsci / jenkinsci/durable-task-plugin
[JENKINS-48415] Pipeline PowerShell won't execute when there's spaces in the path
- Dominant language
- Java
- Stars
- 30
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
When creating a job with a space in the name the "powershell" step in a pipeline will hang.
Steps to reproduce:
- Create a Pipeline with a space in the name (e.g. "A Space").
- Paste in the following pipeline script:
pipeline {
agent any
stages {
stage ("Stage 1") {
steps {
powershell 'Write-Output "Hello world!"'
}}}} - Run the build and see it hang on the PowerShell step.
It looks like it's due to the use of nested double quotes in the command that's called by the plugin, so it's probably ending the string at the wrong point. I copied the generated PowerShell scripts and tried to execute the command myself and got an error only when spaces and double quotes were used.
Manual attempt:
U:\Build Dir>powershell.exe -noninteractive -executionpolicy bypass -command ". "U:\Build Dir\Helper.ps1"; execute-andwriteoutput -mainscript "U:\Build Dir\test.ps1" -logfile "U:\Build Dir\test_log.txt" -resultfile "U:\Build Dir\test_result.txt";"
. : The term 'U:\Build' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ . U:\Build Dir\Helper.ps1; execute-andwriteoutput -mainscript U:\Bui ...
+ ~~~~~~~~
{{ + CategoryInfo : ObjectNotFound: (U:\Build:String) [], CommandNotFoundException}}
{{ + FullyQualifiedErrorId : CommandNotFoundException}}execute-andwriteoutput : The term 'execute-andwriteoutput' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:29
+ . U:\Build Dir\Helper.ps1; execute-andwriteoutput -mainscript U:\Bui ...
+ ~~~~~~~~~~~~~~~~~~~~~~
{{ + CategoryInfo : ObjectNotFound: (execute-andwriteoutput:String) [], CommandNotFoundException}}
{{ + FullyQualifiedErrorId : CommandNotFoundException}}
---
Originally reported by mcaley, imported from: Pipeline PowerShell won't execute when there's spaces in the path
Raw content of original issue
When creating a job with a space in the name the "powershell" step in a pipeline will hang.
Steps to reproduce:
- Create a Pipeline with a space in the name (e.g. "A Space").
- Paste in the following pipeline script:
pipeline {
agent any
stages {
stage ("Stage 1") {
steps {
powershell 'Write-Output "Hello world!"'
}}}}
- Run the build and see it hang on the PowerShell step.
It looks like it's due to the use of nested double quotes in the command that's called by the plugin, so it's probably ending the string at the wrong point. I copied the generated PowerShell scripts and tried to execute the command myself and got an error only when spaces and double quotes were used.
Manual attempt:
U:\Build Dir>powershell.exe -noninteractive -executionpolicy bypass -command ". "U:\Build Dir\Helper.ps1"; execute-andwriteoutput -mainscript "U:\Build Dir\test.ps1" -logfile "U:\Build Dir\test_log.txt" -resultfile "U:\Build Dir\test_result.txt";"
. : The term 'U:\Build' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ . U:\Build Dir\Helper.ps1; execute-andwriteoutput -mainscript U:\Bui ...
+ ~~~~~~~~
{{ + CategoryInfo : ObjectNotFound: (U:\Build:String) [], CommandNotFoundException}}
{{ + FullyQualifiedErrorId : CommandNotFoundException}}execute-andwriteoutput : The term 'execute-andwriteoutput' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
At line:1 char:29
+ . U:\Build Dir\Helper.ps1; execute-andwriteoutput -mainscript U:\Bui ...
+ ~~~~~~~~~~~~~~~~~~~~~~
{{ + CategoryInfo : ObjectNotFound: (execute-andwriteoutput:String) [], CommandNotFoundException}}
{{ + FullyQualifiedErrorId : CommandNotFoundException}}
environment
```
Jenkins 2.73.3 on Windows Server 2012 R2
Jenkins 2.93 on Windows 10 Enterprise
```
Contributor guide
Assessment
This issue has not been assessed yet.