Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
598 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 Reply

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) 
                ] 
            ) 
        ]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...