制品库集成
# artifactory
.build:
stage: build
tags:
- build
script:
- $BUILD_SHELL
- ls
.deploy-artifact:
stage: deploy-artifact
tags:
- build
script:
- curl -u${ARTIFACT_USER}:${ARTIFACT_PASSWD} -T ${ARTIFACT_PATH} "$ARTIFACTORY_URL/$ARTIFACTORY_NAME/$TARGET_FILE_PATH/$TARGET_ARTIFACT_NAME"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
定义变量
template
include:
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/build.yml'
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/test.yml'
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/codeanalysis.yml'
variables:
BUILD_SHELL: 'mvn clean package -DskipTests' ##构建命令
CACHE_DIR: 'target/'
TEST_SHELL : 'mvn test' ##测试命令
JUNIT_REPORT_PATH: 'target/surefire-reports/TEST-*.xml' ##单元测试报告
# 代码扫描
SCANNER_HOME : "/usr/local/buildtools/sonar-scanner-3.2.0.1227-linux"
SCAN_DIR : "src"
ARTIFACT_PATH : 'target/*.jar' ##制品目录
#上传制品库
ARTIFACTORY_URL: "http://192.168.1.200:30082/artifactory"
ARTIFACTORY_NAME: "cidevops"
TARGET_FILE_PATH: "$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_ID"
TARGET_ARTIFACT_NAME: "$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_ID.jar"
cache:
paths:
- ${CACHE_DIR}
stages:
- build
- test
- parallel01
build:
stage: build
extends: .build
rules:
- when: on_success
test:
stage: test
extends: .test
rules:
- when: on_success
code_analysis:
stage: parallel01
extends: .codeanalysis-java
codeanalysis_mr:
stage: parallel01
extends: .codeanalysis-mr
deploy_artifact:
stage: parallel01
extends: .deploy-artifact
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
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
下载制品
.down-artifact:
stage: down-artifact
tags:
- build
script:
- curl -u${ARTIFACT_USER}:${ARTIFACT_PASSWD} -O "$ARTIFACTORY_URL/$ARTIFACTORY_NAME/$TARGET_FILE_PATH/$TARGET_ARTIFACT_NAME"
- ls
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
template
down_artifact:
stage: down_artifact
extends: .down-artifact
1
2
3
2
3
# 镜像仓库
https://cr.console.aliyun.com/cn-beijing/instances/repositories
.build-docker:
stage: buildimage
tags:
- build
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWD $CI_REGISTRY
- docker build -t ${IMAGE_NAME} -f ${DOCKER_FILE_PATH} .
- docker push ${IMAGE_NAME}
- docker rmi ${IMAGE_NAME}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
include:
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/build.yml'
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/test.yml'
- project: 'cidevops/cidevops-gitlabci-service'
ref: master
file: 'jobs/codeanalysis.yml'
variables:
BUILD_SHELL: 'mvn clean package -DskipTests' ##构建命令
CACHE_DIR: 'target/'
TEST_SHELL : 'mvn test' ##测试命令
JUNIT_REPORT_PATH: 'target/surefire-reports/TEST-*.xml' ##单元测试报告
# 代码扫描
SCANNER_HOME : "/usr/local/buildtools/sonar-scanner-3.2.0.1227-linux"
SCAN_DIR : "src"
ARTIFACT_PATH : 'target/*.jar' ##制品目录
#上传制品库
ARTIFACTORY_URL: "http://192.168.1.200:30082/artifactory"
ARTIFACTORY_NAME: "cidevops"
TARGET_FILE_PATH: "$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME/$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_ID"
TARGET_ARTIFACT_NAME: "$CI_PROJECT_NAME-$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_ID.jar"
#构建镜像
CI_REGISTRY: 'registry.cn-beijing.aliyuncs.com'
CI_REGISTRY_USER: '610556220zy'
#CI_REGISTRY_PASSWD: 'xxxxxxxx.'
IMAGE_NAME: "$CI_REGISTRY/$CI_PROJECT_PATH:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA-$CI_PIPELINE_ID"
DOCKER_FILE_PATH: "./Dockerfile"
cache:
paths:
- ${CACHE_DIR}
stages:
- build
- test
- parallel01
- down_artifact
build:
stage: build
extends: .build
rules:
- when: on_success
test:
stage: test
extends: .test
rules:
- when: on_success
code_analysis:
stage: parallel01
extends: .codeanalysis-java
codeanalysis_mr:
stage: parallel01
extends: .codeanalysis-mr
deploy_artifact:
stage: parallel01
extends: .deploy-artifact
down_artifact:
stage: down_artifact
extends: .down-artifact
build_image:
stage: parallel01
extends: .build-docker
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
80
81
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
80
81
上次更新: 2024/04/16, 08:52:08