-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile-online
79 lines (76 loc) · 3.07 KB
/
Jenkinsfile-online
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
pipeline {
agent {
node {
label 'maven'
}
}
parameters {
choice(name: 'PROJECT_NAME',choices: ['gulimall-gateway', 'gulimall-product', 'gulimall-cat'],description: '请选择要部署的项目名')
string(name:'PROJECT_VERSION',defaultValue: 'latest',description:'请输入要发布的版本,例:v1.0.0')
}
environment {
ALIYUN_CREDENTIAL_ID = 'aliyun-repo-id'
REGISTRY = 'registry.cn-beijing.aliyuncs.com'
ALIYUN_NAMESPACE = 'aliyun-chengcheng'
GITEE_CREDENTIAL_ID = 'gitee-id'
CODE_URL = 'https://gitee.com/cc950627/gulimall.git'
GITEE_ACCOUNT = 'cc950627'
KUBECONFIG_CREDENTIAL_ID = 'demo-kubeconfig'
}
stages {
stage('代码拉取') {
steps {
git(url: "$CODE_URL", credentialsId: "$GITEE_CREDENTIAL_ID", branch: "$BRANCH_NAME", changelog: true, poll: false)
}
}
stage('编译打包') {
steps {
container ('maven') {
sh "mvn -f gulimall-common -Dmaven.test.skip=true -gs `pwd`/settings.xml clean"
sh "mvn -f gulimall-common -Dmaven.test.skip=true -gs `pwd`/settings.xml install"
sh "mvn -f $PROJECT_NAME -Dmaven.test.skip=true -gs `pwd`/settings.xml package"
}
}
}
stage('构建镜像') {
steps {
container ('maven') {
sh "docker build -f $PROJECT_NAME/Dockerfile -t $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER ."
}
}
}
stage('推送镜像') {
steps {
container ('maven') {
withCredentials([usernamePassword(passwordVariable : 'ALIYUN_PASSWORD' ,usernameVariable : 'ALIYUN_USERNAME' ,credentialsId : "$ALIYUN_CREDENTIAL_ID")]) {
sh "echo $ALIYUN_PASSWORD | docker login --username=$ALIYUN_USERNAME $REGISTRY --password-stdin"
sh "docker tag $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:$BRANCH_NAME-latest"
sh "docker push $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:$BRANCH_NAME-$PROJECT_VERSION"
}
}
}
}
stage('部署') {
steps {
kubernetesDeploy(configs: "$PROJECT_NAME/deploy/**", enableConfigSubstitution: true, kubeconfigId: "$KUBECONFIG_CREDENTIAL_ID")
}
}
stage('发布版本'){
when{
expression{
return params.PROJECT_VERSION != latest
}
}
steps {
container ('maven') {
withCredentials([usernamePassword(credentialsId: "$GITEE_CREDENTIAL_ID", passwordVariable: 'GITEE_PASSWORD', usernameVariable: 'GITEE_USERNAME')]) {
sh "git tag -a $PROJECT_VERSION -m $PROJECT_VERSION"
sh "git push http://$GITEE_USERNAME:$GITEE_PASSWORD@gitee.com/$GITHUB_ACCOUNT/gulimall.git --tags --ipv4"
}
sh "docker tag $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:$BRANCH_NAME-$PROJECT_VERSION"
sh "docker push $REGISTRY/$ALIYUN_NAMESPACE/$PROJECT_NAME:$BRANCH_NAME-$PROJECT_VERSION"
}
}
}
}
}