jenkins之devops集成CD工具

安装saltstack

yum仓库配置

curl -fsSL https://mirrors.aliyun.com/saltstack/py3/redhat/7/x86_64/3004.repo >  /etc/yum.repos.d/salt.repo 
sudo sed -i "s/repo.saltproject.io/mirrors.aliyun.com\/saltstack/g" /etc/yum.repos.d/salt.repo 

 安装主节点与从节点

sudo yum install salt-master salt-minion

  配置master 与从节点通讯

[root@jenkins ~]# vim /etc/salt/minion

##### Primary configuration settings #####
##########################################
# This configuration file is used to manage the behavior of the Salt Minion.
# With the exception of the location of the Salt Master Server, values that are
# commented out but have an empty line after the comment are defaults that need
# not be set in the config. If there is no blank line after the comment, the
# value is presented as an example and is not the default.

# Per default the minion will automatically include all config files
# from minion.d/*.conf (minion.d is a directory in the same directory
# as the main minion config file).
#default_include: minion.d/*.conf

# Set the location of the salt master server. If the master server cannot be
# resolved, then the minion will fail to start.
master: 192.168.40.40   #添加master IP
[root@jenkins ~]# systemctl restart salt-master.service 
[root@jenkins ~]# systemctl restart salt-minion.service 
[root@jenkins ~]# salt-key -L
Accepted Keys:
Denied Keys:
Unaccepted Keys:
jenkins
Rejected Keys:
[root@jenkins ~]# salt-key -a jenkins
The following keys are going to be accepted:
Unaccepted Keys:
jenkins
Proceed? [n/Y] y
Key for minion jenkins accepted.
[root@jenkins ~]# salt-key -L
Accepted Keys:
jenkins
Denied Keys:
Unaccepted Keys:
Rejected Keys:

  测试联通性

[root@jenkins ~]# salt "jenkins" test.ping
jenkins:
    True

  流水线

image

 代码

package org.devops
//saltstack
def SaltDeploy(hosts,func){
    sh "salt \"${hosts}\" ${func} "
}

 

流水线

#!groovy
@Library('jenkinslibrary@master') _
def build = new org.devops.build()
def deploy = new org.devops.deploy()
String buildShell = "${env.buildShell}"
String buildType = "${env.buildType}"
pipeline{
    agent { node { label "masetr"}}
    stages{
        stage("build"){
            steps{
                script{  
                    build.Build(buildType, buildShell)
                    deploy.SaltDeploy("jenkins","test.ping")
                }
            }
        }
    }
}

  ansible 工具

 yum install epel* 
 yum install -y ansible

  配置

[root@jenkins ~]# vim /etc/ansible/hosts
[servers]
server1 ansible_ssh_host=192.168.40.40



 ssh-keygen 

 ssh-copy-id 192.168.40.40

  流水线参数

image

image

 

image

 

 脚本

#!groovy
@Library('jenkinslibrary@master') _
def build = new org.devops.build()
def deploy = new org.devops.deploy()
String buildShell = "${env.buildShell}"
String buildType = "${env.buildType}"
pipeline{
    agent { node { label "masetr"}}
    stages{
        stage("build"){
            steps{
                script{  
                    build.Build(buildType, buildShell)
                   // deploy.SaltDeploy("jenkins","test.ping")
                    deploy.AnsibleDeploy("${deployHosts}","-m ping")
                }
            }
        }
    }
}

  

 

  

posted @ 2026-05-28 11:25  烟雨楼台,行云流水  阅读(3)  评论(0)    收藏  举报