import hudson.*
pipeline{
agent any
stages{
stage("Download code"){
steps{
script{
environment {
http_proxy="xx.xx.xx.xx:xxxx"
https_proxy="xx.xx.xx.xx:xxxx"
}
cleanWs()
checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxxx-xxx-xx-xx-xxx', url: 'ssh://user@xx.xx.xx.xx:xxxx/a.git']]])
git_commit=sh (script: '#!/bin/sh -e
'+'git rev-parse --short HEAD', returnStdout: true).trim()
}
}
}
stage("docker push"){
steps{
script{
tag_name=git_commit[0..8]
test_unit="test-unit"
testcase_ver="v1.0"
ip="xx.xx.xx.xx"
port="5000"
docker_name=sh (script: '#!/bin/bash -e
'+"""echo $test_unit | sed "s/robot-test/&-$testcase_ver/g" """, returnStdout: true).trim()
sh (script: '#!/bin/bash -e
'+"""
cp //home/test/script/Dockerfile .
docker build -t $docker_name .
docker images | grep ^$docker_name
docker tag $docker_name $ip:$port/$docker_name:$tag_name
docker tag $ip:$port/$docker_name:$tag_name $ip:$port/$docker_name:latest
docker push $ip:$port/$docker_name
echo "############ Finished ############"
""")
println "############ Remove local docker images ############"
sh (script: '#!/bin/bash -e
'+"""
docker rmi $ip:$port/$docker_name:$tag_name
docker rmi $ip:$port/$docker_name:latest
docker rmi $docker_name
""")
}
}
}
}
post{
always{
emailext attachLog: true,
body: '$DEFAULT_CONTENT',
subject: '$DEFAULT_SUBJECT',
to: 'admin11@163.com'
}
}
}