当前位置:网站首页>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.
边栏推荐
猜你喜欢

毕业五年,想当初若没有入行测试,我是否还会如这般焦虑

注册设备监理师难考吗,和监理工程师有什么关系?

Deflection lock / light lock / heavy lock lock is healthier. How to complete locking and unlocking

报错:Internal error XFS_WANT_CORRUPTED_GOTO at line 1635 of file fs/xfs/libxfs/xfs_alloc.c.

微信小程序怎么实现圆心进度条

MySQL高级篇3

偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的

MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级等

go搭建服务器基础

Lumiprobe biotin phosphimide (hydroxyproline) instructions
随机推荐
Lumiprobe nucleic acid quantitative qudye dsDNA br detection kit
Go语学习笔记 - gorm使用 - 数据库配置、表新增 | Web框架Gin(七)
片荒吗?不用下载直接在线免费看的资源来了!2022年收藏夹必须有它!
ssh-server配置文件参数PermitRootLogin介绍
遇到“word在试图打开文件时遇到错误”怎么办?
多态在代码中的体现
减少嵌入式软件调试时间的三个技巧
Label Contrastive Coding based Graph Neural Network for Graph Classification
qiao-npms:搜索npm包
Personal developed penetration testing tool Satania
凤凰架构——架构师的视角
Qiao NPMS: search for NPM packages
MySQL introduction, detailed installation steps and usage | dark horse programmer
阿里kube-eventer mysql sink简单使用记录
Study on lumiprobe dye NHS ester BDP FL NHS ester
Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
Testing principle and precautions of biovendor rage ELISA Kit
Icml2022 | utility theory of sequential decision making
利用日志服务器输出各种apache的日志的TOPN