Usually when executing multiple shell commands i use multiline strings:
bat """
-cmd1
-cmd2 ...
"""
but when using withCredentials[…]
i have to do bat 'cmd %credential% cmd2'
to interpolate correctly
But this gives me an error because it just sees it as one command. What is the correct way to do this?
Jenkins setup:Jenkins 2.426.1
1 Like
mawinter69
(Markus Winter)
2
bat '''
cmd %credential%
cmd2
'''
but for windows batch you can also use double quotes I think as %variable%
is not interpolated by groovy so it reaches as is the windows batch
1 Like
Indeed, works. But one more question
when i defined a normal variable how do i use it in there as well?
def path = "path\\folder"
with Credentials [...] {
bat '''
cd %path%
cmd %credential%
cmd2
'''
}
the path evaluates to nothing here
Yes double quotes work too but interpolate unsafely and give a warning.
mawinter69
(Markus Winter)
4
withEnv(["path=path\\folder"]) {
with Credentials [...] {
bat '''
cd %path%
cmd %credential%
cmd2
'''
}
}