I am using a customized Groovy shared library in my Jenkinsfile.
during the Jenkinsfile I have this Groovy commands array list:
commands = [
"pwd",
"ls -la",
"some predefined groovy closure",
"cd /tmp",
"some predefined groovy closure2",
"pwd",
"ls -la"
]
I want to execute the Shell commands in the same Shell so I have the context from previous commands, but also execute the commands and closures in the order they appear in the 'commands' array list.
It'll be best if all the commands and closures will be executed in the same shell. But first step is to make all shell commands run in the same shell.
I also want the output from the commands to be printed to my Jenkins build logs right after execution (live output will be best).
I tried using screen
to create a new Shell screen and execute the Shell commands on it, but I run my Jenkins as a master OS4 pod, and the workers as dynamic pods that run as builds are triggered, so I don't actually have a terminal, which made the screen commands fail.
This is an example of a stage in my pipeline that uses:
def ansibleTowerPlugin = {
ansibleTower (
//////plugin configuration
)
}
genStage(
title: "deploy with awx",
containerName: "example"
commands: [
'pwd',
'ls -la',
ansibleTowerPlugin,
'cd ./example_dir',
{
sh "echo testing" //testing closure
},
'pwd',
'ls -la'
]
)
],
[
costumeContainerTemplates: [
name: "example"
image: "artifctory/example/image:tag"
alwaysPullImage: "true"
]
)
I used to execute the shell commands like this (before I added the closures):
sh argsmands.join(" && ")
but this does not work with the closures.
Would love some help if anyone has an idea