jenkins - execute Shell commands in the same Shell non sequentially - Stack Overflow

I am using a customized Groovy shared library in my Jenkinsfile.during the Jenkinsfile I have this Gro

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745154316a4614024.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信