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"
"""
}
}