You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
node('haimaxy-jnlp') {
|
|
stage('Clone') {
|
|
echo "1.Clone Stage"
|
|
// git url: "https://github.com/cnych/jenkins-demo.git"
|
|
// checkout scm
|
|
script {
|
|
build_tag = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
|
|
|
|
// if (env.BRANCH_NAME != 'master') {
|
|
// build_tag = "${env.BRANCH_NAME}-${build_tag}"
|
|
// }
|
|
}
|
|
}
|
|
stage('Test') {
|
|
echo "2.Test Stage"
|
|
}
|
|
stage('Build') {
|
|
echo "3.Build Docker Image Stage"
|
|
sh "docker build -t 120.78.76.88/cnych/jenkins-demo:${build_tag} ."
|
|
}
|
|
stage('Push') {
|
|
echo "4.Push Docker Image Stage"
|
|
withCredentials([usernamePassword(credentialsId: 'qniao-harbor-88', passwordVariable: 'qniao-harbor-88Password', usernameVariable: 'qniao-harbor-88User')]) {
|
|
sh "docker login -u ${qniao-harbor-88User} -p ${qniao-harbor-88Password} 120.78.76.88"
|
|
sh "docker push 120.78.76.88/cnych/jenkins-demo:${build_tag}"
|
|
}
|
|
}
|
|
stage('YAML') {
|
|
echo "5. Change YAML File Stage"
|
|
def userInput = input(
|
|
id: 'userInput',
|
|
message: 'Choose a deploy environment',
|
|
parameters: [
|
|
[
|
|
$class: 'ChoiceParameterDefinition',
|
|
choices: "Dev\nQA\nProd",
|
|
name: 'Env'
|
|
]
|
|
]
|
|
)
|
|
echo "This is a deploy step to ${userInput.Env}"
|
|
sh "sed -i 's/<BUILD_TAG>/${build_tag}/' k8s.yaml"
|
|
sh "sed -i 's/<BRANCH_NAME>/${env.BRANCH_NAME}/' k8s.yaml"
|
|
}
|
|
stage('Deploy') {
|
|
echo "6. Deploy Stage"
|
|
if (userInput.Env == "Dev") {
|
|
// deploy dev stuff
|
|
} else if (userInput.Env == "QA"){
|
|
// deploy qa stuff
|
|
} else {
|
|
// deploy prod stuff
|
|
// input "确认要部署线上环境吗?"
|
|
}
|
|
sh "kubectl apply -f k8s.yaml"
|
|
}
|
|
}
|