-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
122 lines (112 loc) · 3.48 KB
/
.gitlab-ci.yml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
stages:
- build
- test
build-container:
stage: build
image: docker:20.10.16
variables:
DOCKER_IMAGE_TAG: latest
DOCKER_TLS_CERTDIR: "/certs"
services:
- docker:20.10.16-dind
allow_failure: false
before_script:
- docker info
- echo "$DOCKER_REGISTRY_PASS" | docker login --username $DOCKER_REGISTRY_USER --password-stdin
- echo "$GITLAB_REGISTRY_TOKEN" | docker login registry.gitlab.com --username $GITLAB_REGISTRY_USER --password-stdin
script:
- docker build -t cypher0n3/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG .
- echo "====== Checking Container ======"
- working_dir="$(pwd)"
- test1_output="$(docker run cypher0n3/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG)"
- echo "${test1_output}"
- if [[ "${test1_output}" == "" ]]; then exit 1; else echo "Test 1 passed."; fi
- test2_output="$(docker run -v $working_dir/test:/test cypher0n3/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG Invoke-ScriptAnalyzer -Path /test/*.ps1)"
- echo "${test2_output}"
- if [[ "${test2_output}" == "" ]]; then exit 2; else echo "Test 2 passed."; fi
- echo "====== Uploading Container ======"
- docker tag cypher0n3/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG registry.gitlab.com/cypher_zero/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG
- docker push cypher0n3/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG
- docker push registry.gitlab.com/cypher_zero/psscriptanalyzer-docker:$DOCKER_IMAGE_TAG
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "manual"
- if: $CI_COMMIT_BRANCH == "master"
build-tag:
stage: build
extends: build-container
variables:
DOCKER_IMAGE_TAG: $CI_COMMIT_TAG
rules:
- if: $CI_COMMIT_TAG
build-test:
stage: build
extends: build-container
variables:
DOCKER_IMAGE_TAG: $CI_MERGE_REQUEST_IID
rules:
- if: $CI_MERGE_REQUEST_IID
.test-container:
stage: test
image:
name: registry.gitlab.com/cypher_zero/psscriptanalyzer-docker:latest
entrypoint: ["/bin/bash", "-c"]
variables:
DOCKER_IMAGE_TAG: $CI_MERGE_REQUEST_IID
PS1_TESTPATH: ./test/*.ps1
FAIL_MSG: Failures detected; see above.
EXIT_ERR_CODE: 1
script:
- output=$(pwsh -c "Invoke-ScriptAnalyzer -Path $PS1_TESTPATH")
- echo "${output}"
- |
if [[ -n ${output} ]]; then
echo "$FAIL_MSG"
exit $EXIT_ERR_CODE
fi
rules:
- if: $CI_MERGE_REQUEST_IID
pass-test-container:
extends: .test-container
variables:
PS1_TESTPATH: ./test/TestScript-Pass.ps1
fail-test-container:
extends: .test-container
variables:
PS1_TESTPATH: ./test/TestScript-Fail.ps1
FAIL_MSG: Failures detected (which is expected); see above.
EXIT_ERR_CODE: 0
pass-test-container-scheduled:
extends: pass-test-container
variables:
DOCKER_IMAGE_TAG: latest
needs:
- build-container
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "manual"
- if: $CI_COMMIT_BRANCH == "master"
fail-test-container-scheduled:
extends: fail-test-container
variables:
DOCKER_IMAGE_TAG: latest
needs:
- build-container
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "manual"
- if: $CI_COMMIT_BRANCH == "master"
pass-test-container-tag:
extends: pass-test-container
variables:
DOCKER_IMAGE_TAG: $CI_COMMIT_TAG
rules:
- if: $CI_COMMIT_TAG
fail-test-container-tag:
extends: fail-test-container
variables:
DOCKER_IMAGE_TAG: $CI_COMMIT_TAG
rules:
- if: $CI_COMMIT_TAG
...