yudong
pipeline {
agent {
node {
label 'maven'
}
}
stages {
stage('拉取代码') {
agent none
steps {
git(url: 'git@codeup.aliyun.com:64c31ce1d25b60178661095b/xxx/xxx-xxx/xxx-xxx-server.git', credentialsId: 'xxx-ssh', branch: 'master', changelog: true, poll: false)
}
}
stage('构建') {
agent none
steps {
container('maven') {
sh 'mvn -Dmaven.test.skip=true -gs /opt/apache-maven/conf/settings.xml clean package'
sh ''
withCredentials([usernamePassword(credentialsId: 'xxx-docker-image', passwordVariable: 'DOCKER_PASSWORD', usernameVariable: 'DOCKER_USERNAME')]) {
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh '''apk add docker
docker build -f Dockerfile -t $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BUILD_NUMBER .'''
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER'
}
}
}
}
stage('推送 latest') {
agent none
when {
branch 'master'
}
steps {
container('maven') {
sh 'docker tag $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
sh 'docker push $REGISTRY/$DOCKERHUB_NAMESPACE/$APP_NAME:latest '
}
}
}
stage('部署到 dev') {
agent none
steps {
container('maven') {
input(message: '@project-admin', submitter: '')
withCredentials([kubeconfigContent(credentialsId : 'KUBECONFIG_CREDENTIAL_ID' ,variable : 'KUBECONFIG_CONFIG' ,)]) {
sh 'mkdir -p \~/.kube/'
sh 'echo "$KUBECONFIG_CONFIG" > \~/.kube/config'
sh 'envsubst < deploy/dev-ol/deploy.yaml | kubectl apply -f -'
}
}
}
}
}
environment {
DOCKER_CREDENTIAL_ID = 'dockerhub-id'
GITHUB_CREDENTIAL_ID = 'github-id'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
REGISTRY = 'docker.io'
DOCKERHUB_NAMESPACE = 'docker_username'
GITHUB_ACCOUNT = 'kubesphere'
APP_NAME = 'devops-java-sample'
}
parameters {
string(name: 'TAG_NAME', defaultValue: '', description: '')
}
}
Jenkinsfile文件内容是这些