当前位置:网站首页>How to run jenkins build, in multiple servers with ssh-key
How to run jenkins build, in multiple servers with ssh-key
2022-06-30 21:10:00 【weixin_ eight hundred and eighty-eight thousand nine hundred an】
Trying to figure out how can I run a Jenkins build on multiple servers with my ssh-key connection.
For now I used SSH remote host plugin, but this plugin is good for 1,2,3,4.. servers and not for 100+.
I googleit and I found that many people offer a solution to use Ansible but i have no experience in ansible so if anyone has some examples for this process to run build on multiple servers with ansible or with any other way, I'll be happy to hear.
I'm running Jenkins-Master on windows and Jenkins-Slave on Linux(ubuntu).
This is a pretty simplified example, but for a freestyle job, I think it breaks down into the following steps:
install ansible on the jenkins-agent.
pip install ansibleorapt install ansibleLoad your ssh key into Jenkins credentials store. I assume here that you use the credential store plugin (but you could also load it into an ssh-agent, or use some other method to expose the key on the jenkins-agents.)
i) Manage jenkins -> Manage Credentials
ii) add credentials -> "SSH username with private key"
iii) paste in they key and give it a name like "SSH_KEY_ANSIBLE"
- Create a new Jenkins freestyle job and add credentials (SSH_KEY_ANSIBLE)
i) Go to Build Environment section of job configuration
ii) check "Use secret text(s) or file(s)"
iii) add binding item "SSH User Private Key" to SSH_KEY_ANSIBLE
iv) set the Username variable to SSH_USER, set the key file to SSH_KEY
- add your list of hosts to your ansible inventory file on jenkins-agent: /etc/ansible/hosts
[jenkins_job_hosts] myhost1 myhost2 ... myhost101
- Create a playbook on the jenkins agent, for example
/home/jenkins/ansible/my_first_playbook.yml:
--- - hosts: jenkins_job_hosts tasks: - command: date - debug: msg: add other ansible tasks here....
- Go to build section in jenkins job.
i) add an "Execute shell" build step.
ii) use the following to run the ansible against all your hosts
ansible-playbook --private-key ${SSH_KEY} \
-u ${SSH_USER} \
-i /etc/ansible/hosts \
/home/jenkins/ansible/my_first_playbook.yml
Extra steps
You can put your inventory file and playbook into git, and check them out into the job
Also you can look at pipeline jobs in groovy syntax in a Jenkinsfile, which simplifies managing the job.
边栏推荐
猜你喜欢

多态在代码中的体现

uniapp-生命周期/路由跳转

Apply for vector bus protocol color picture wallpaper hanging picture, very good!

科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?

申请Vector 总线协议彩图壁纸挂画,非常棒哦!

双立体柱状图/双y轴

【微服务~Nacos】Nacos之配置中心
![翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]](/img/a8/6472e2051a295f5e42a88d64199517.png)
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]

Lumiprobe copper free click chemical solution

Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid
随机推荐
文本生成模型退化怎么办?SimCTG 告诉你答案
将博客搬至CSDN
两个skyline
SQL必需掌握的100个重要知识点:创建和操纵表
A small step in code change and a big leap in thinking
Peking University ACM problems 1004:financial management
学习总结
Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid
Peking University ACM problems 1000:a+b problem
Text recognition svtr paper interpretation
有趣插件汇总
开源实习经验分享:openEuler软件包加固测试
Oracle 数据库表结构 Excel 导出
Game 81 biweekly
毕业设计
时空数据挖掘:综述
ncat详细介绍(转载)
SqlServer 获取字符串中数字,中文及字符部分数据
Spatiotemporal data mining: an overview
Lumiprobe copper free click chemical solution