Issue
According to the docs, one can have multiple lines in the script
paramater of bat
.
However, I've tried the following in my stage steps and only the first line gets executed.
Declarative pipeline:
...
bat """
c:\\path\\to\\conda activate my_env
cd c:\\path\\to\\scripts
python myscript.py ${some_arg}
"""
...
Scripted pipeline:
...
bat(
returnStdout: true,
script: """
c:\\path\\to\\conda activate my_env
cd c:\\path\\to\\scripts
python myscript.py ${some_arg}
"""
)
...
What do I need to do to get all the lines to execute sequentially?
PS
I know I can chain the commands into a single line with "&" but that quickly becomes unreadable with lots of commands.
Solution
You need to add the keyword call
, whereever you are invoking Windows batch scripts (.bat
or .cmd
), else the executed batch file won't return control. E.g.:
...
bat """
call c:\\path\\to\\conda activate my_env
cd c:\\path\\to\\scripts
call python myscript.py ${some_arg}
"""
...
Answered By - user_9090
Answer Checked By - Marie Seifert (JavaFixing Admin)