Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

triggers - Execute a Jenkins pipeline on remote host without a slave

My Jenkins is on host1 and I wish to trigger ansible which is on host2 using Jenkins pipeline. This can be done by creating a slave node on host2 and specifying agent in Jenkins pipeline.

However, I do not have a Jenkins slave on host2.

Instead, Jenkins has connectivity to host2 by means of Server Groups Center which can be found under Jenkins Global Configuration

Do I need a Jenkins slave on host2 ? If not, then how can I use Server Groups Center in Jenkins pipeline to trigger Ansible on host2? Sample code please…


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Do I need a Jenkins slave on host2?

No, if you have Linux on host2: you can simply run any command over SSH.

How can I use Server Groups Center in Jenkins pipeline to trigger Ansible on host2?

Server Groups Center block comes from SSH2 Easy plugin, which is very old and doesn't support Jenkins pipeline. So you can't use information from that block of settings in your pipeline.

But there are other plugins for SSH; try Publish over SSH plugin for example. This plugin adds Publish over SSH block to Jenkins Global Configuration, where you can specify host2 connection parameters.

And then you can write pipeline step as follows ({HOST2} is the name of host2 that you type in Publish over SSH block in Jenkins Global Configuration):

steps {
    sshPublisher 
        failOnError: true, 
        publishers: [ 
            sshPublisherDesc( 
                configName: "{HOST2}", 
                transfers: [ 
                    sshTransfer (execCommand: "ansible -m ping all -i inventory_file", execTimeout: 120000) 
                ] 
            ) 
        ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...