jenkins migration

deploy.sh

#!/bin/bash
docker load -i /tmp/nginx/images/*

startsvc.sh

#!/bin/bash
/opt/bin/kubectl --server=127.0.0.0:8888 create -f  /tmp/nginx/yaml/cluster/nginx-service.yaml
/opt/bin/kubectl --server=127.0.0.0:8888 create -f  /tmp/nginx/yaml/cluster/nginx-rc.yaml

stopsvc.sh

#!/bin/bash
/opt/bin/kubectl --server=127.0.0.0:8888 delete -f  /tmp/nginx/yaml/cluster/nginx-service.yaml
/opt/bin/kubectl --server=127.0.0.0:8888 delete -f  /tmp/pco-nginx/pco-ui/nginx/yaml/cluster/nginx-rc.yaml
sleep 10
/opt/bin/kubectl --server=127.0.0.0:8888 get -all -namespaces svc|grep pco

jenkinsfile

pipeline{
 agent{}
 options{}
 environment{}
 post{}
 stages{
 stage('checkout'){}
 stage('clean'){ }
 stage('docker'){
    steps{
  script{
  DockerfileContent=""" xxx"""
  writeFile(encoding : 'UTF-8',file : "Dockerfile",text :DockerfileContent )
  sh"""  docker login.....docker build -t ...mkdir....docker save ..."""
  }
  }
    }
 stage('package'){
    steps{
    sh"""
    cp deploy.sh  pathfile
    cp startsvc.sh  pathfile
    cp stopsvc.sh  pathfile
    tar -czvf pathfile tarfile
    """
    }
    }
 stage('publish'){ when {expression{env.BUILD_VERSION==~'^PUB.*'}}}
 stage('deploy1'){
        when {expression{env.BUILD_VERSION==~'^SE.*'}}
       sshagent(['master']) {
        sh """ scp -r - o StrictHostKeyChecking=no tarfile dirfile"""
        sh""" ssh -o StrictHostKeyChecking=no -l user passwd cmd
    }
 stage('deploy2'){when {expression{env.BUILD_VERSION==~'^SE.*'}}}
 stage('deploy3'){when {expression{env.BUILD_VERSION==~'^SE.*'}}}
  }

}

better jenkinsfiile with ansible

pipeline{
 agent{}
 options{}
 environment{}
 post{}
 stages{
 stage('checkout'){}
 stage('clean'){ }
 stage('docker'){
    steps{
  script{
  DockerfileContent=""" xxx"""
  writeFile(encoding : 'UTF-8',file : "Dockerfile",text :DockerfileContent )
  sh"""  docker login.....docker build -t ...mkdir....docker save ..."""
  }
  }
    }
 stage('package'){
    steps{
    sh"""
    cp deploy.sh  pathfile
    cp startsvc.sh  pathfile
    cp stopsvc.sh  pathfile
    tar -czvf pathfile tarfile
    """
    }
    }
 stage('publish'){ when {expression{env.BUILD_VERSION==~'^PUB.*'}}}
 stage('deploy'){
        when {expression{env.BUILD_VERSION==~'^SE.*'}}
       sshagent(['master']) {
        sh """ scp -r - o StrictHostKeyChecking=no tarfile dirfile"""
        sh""" 
ssh - o StrictHostKeyChecking=no -l username ip ansible controller -m copy -a"src=.. dest=.."
ssh - o StrictHostKeyChecking=no -l username ip ansible controller -m command -a"tar ..chmod..sh"
"""
    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Jenkins是一款能提高效率的软件,它能帮你把软件开发过程形成工作流,典型的工作流包括以下几个步骤 开发 提交 ...
    jony456123阅读 1,861评论 0 2
  • Jenkins是一款能提高效率的软件,它能帮你把软件开发过程形成工作流,典型的工作流包括以下几个步骤 开发 提交 ...
    程序员在深圳阅读 172,955评论 12 175
  • 参考文档 https://www.linuxidc.com/Linux/2017-09/146760.htmhtt...
    三杯水Plus阅读 4,505评论 0 8
  • 周日咨询,中饭到两点半才吃,家长过来体验书法,注意到孩子专注力不够,运用家庭教育的观念与之交谈,深的家长认可。 学...
    英国红茶阅读 236评论 0 1
  • 华子的人生蜕变之旅原创第518篇 2018年5月18日 星期五 多云(农历四月初四) 上面图片是誉仔今天的...
    誉仔妈妈阅读 698评论 3 8

友情链接更多精彩内容