Someone from Stackoverflow answered the same question I posted there

sh(label: 'Git Submodule Checkout', script: "git submodule foreach 'git 
checkout feature/test-new-scripts || git checkout master'") 

On Wednesday, July 12, 2023 at 10:50:01 PM UTC-4 zil...@gmail.com wrote:

> I can execute the following on a command line, where I just want to 
> checkout a feature/* branch, and if the sub module does not have it, I 
> want to checkout master.
> $ git submodule foreach 'git checkout feature/test-new-scripts || git 
> checkout master'
>
> However, if I execute the same command in a Jenkins pipeline, I get a 
> syntax error.
> sh """
>  git submodule foreach \\'git checkout feature/test-new-scripts || git 
> checkout master\\' 
> """ 
>
> I get the following error
> + git submodule foreach "git checkout feature/test-new-scripts
> Entering 'module1' 
> "git: 1: "git: Syntax error: Unterminated quoted string
> fatal: run_command returned non-zero status for module1 
> . 
> + git checkout master" error: pathspec 'master"' did not match any 
> file(s) known to git
>
> I've tried the following syntax, where I just changed the single quotes (
> '...') in the command itself to double quotes ("..."), to no avail
> sh """
>  git submodule foreach \\"git checkout feature/test-new-scripts || git 
> checkout master\\"
> """
>
> What is the correct syntax do accomplish what I want to do? TIA
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/73af3f9e-28e3-41ee-8733-232fe1c04e94n%40googlegroups.com.

Reply via email to