| Workaround recipe: 1) Identify additional environment variables and their values when starting the msys2 bash via start menu vs by invoking bash.exe from cmd.exe. 2) Create bash skript that sets these environment variables in multiple export NAME=value lines, also add the extended PATH value. Store as jenkins.env in msys2 root folder. 3) In the Jenkinsfiles, define custom step windows_bash
def windows_bash(command) {
bat ('C:\\msys64\\usr\\bin\\bash -c "source /jenkins.env && ' + command + ' "')
}
4) In the Jenkinsfiles, define a delegating custom step that forwards to either sh or windows_bash depending on the operating system of the Agent
def bash(command) {
windows() ? windows_bash(command) : sh(command)
}
where windows() has to be defined to return true only for windows agents. 5) In all places in the Jenkinsfile where a shell command could be executed either on windows or on Unix, use bash "command" instead of sh "command" |