jenkins通过流水线作业pipiline部署
服务器
192.168.89.135
192.168.89.136
192.168.89.141
jenkins 构建两个item,一个build,一个deploy
build不说了
主要说下deploy。
增加两个参数选择,需要发布的项目。这里我们主要发布eureka
application.yml 配置文件
#注册中心 eureka: instance: hostname: eureka prefer-ip-address: true client: register-with-eureka: false fetch-registry: false service-url: defaultZone: http://myhost1:8761/eureka/,http://myhost2:8761/eureka/,http://myhost3:8761/eureka/ server: eviction-interval-timer-in-ms: 30000 enable-self-preservation: false renewal-percent-threshold: 0.9
运行编译脚本:
def EUREKA_HOST_A="192.168.89.136"
def EUREKA_HOST_A_NAME="myhost1"
def EUREKA_HOST_B="192.168.89.141"
def EUREKA_HOST_B_NAME="myhost2"
def EUREKA_HOST_C="192.168.89.135"
def EUREKA_HOST_C_NAME="myhost3"
def EUREKA_PORT="8761"
sh "docker run --restart=always -p ${EUREKA_PORT}:8761 "+ "-d -v ${LOG_PATH}:${LOG_PATH} "+ "-m 1000M --memory-swap -1 "+ "-e eureka.instance.hostname=${my_hostname} "+ "-e eureka.instance.prefer-ip-address=false "+ "-e eureka.client.register-with-eureka=true "+ "-e eureka.client.fetch-registry=true "+ "--add-host=${EUREKA_HOST_A_NAME}:${EUREKA_HOST_A} --add-host=${EUREKA_HOST_B_NAME}:${EUREKA_HOST_B} --add-host=${EUREKA_HOST_C_NAME}:${EUREKA_HOST_C} "+ // 显示真正IP端口 "-e eureka.instance.instance-id=${nodeIp}:${EUREKA_PORT} "+ "--name ${PROJECT_NAME} "+ " $REPOSITORY"
发布后。容器正常运行