generated from snow-actions/composite-action-template
-
Notifications
You must be signed in to change notification settings - Fork 1
248 lines (214 loc) · 8.92 KB
/
test.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: Test
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
jobs:
test-mount:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./
with:
jenkins_home: test-resources/jenkins_home
- run: curl $JENKINS_URL
# Environment variables
- run: test -n "$JENKINS_HOME"
- run: test -n "$JENKINS_VERSION"
- run: test "$JENKINS_URL" = "http://localhost:8080"
- run: test -n "$COMPOSE_FILE"
# Remote Access API
# https://www.jenkins.io/doc/book/using/remote-access-api/
- run: |
crumb=$(curl -sS -c cookie $JENKINS_URL/crumbIssuer/api/json)
echo "CRUMB_HEADER=$(echo $crumb | jq -r '.crumbRequestField'): $(echo $crumb | jq -r '.crumb')" >> $GITHUB_ENV
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 2
- run: curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/job/job-1/build
# Jenkins CLI
# https://www.jenkins.io/doc/book/managing/cli/
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket help
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket build job-1 -f -v
- run: java -jar jenkins-cli.jar -webSocket build job-2 -f -v -p param_1=p1
# Access Jenkins container
# https://github.com/jenkinsci/docker
- run: docker compose ps
- run: docker compose run --rm jenkins --version
- run: docker compose exec jenkins jenkins-plugin-cli --list
test-mount-default:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./
- run: curl $JENKINS_URL
# Environment variables
- run: test "$JENKINS_HOME" = "$RUNNER_TEMP/jenkins_home"
- run: test -n "$JENKINS_VERSION"
- run: test "$JENKINS_URL" = "http://localhost:8080"
- run: test -n "$COMPOSE_FILE"
# Remote Access API
# https://www.jenkins.io/doc/book/using/remote-access-api/
- run: |
crumb=$(curl -sS -c cookie $JENKINS_URL/crumbIssuer/api/json)
echo "CRUMB_HEADER=$(echo $crumb | jq -r '.crumbRequestField'): $(echo $crumb | jq -r '.crumb')" >> $GITHUB_ENV
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 0
# Jenkins CLI
# https://www.jenkins.io/doc/book/managing/cli/
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket help
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: test $(java -jar jenkins-cli.jar -webSocket list-plugins | wc -l) -gt 50
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket create-job job-1 < test-resources/jenkins_home/jobs/job-1/config.xml
- run: java -jar jenkins-cli.jar -webSocket create-job job-2 < test-resources/jenkins_home/jobs/job-2/config.xml
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket build job-1 -f -v
- run: java -jar jenkins-cli.jar -webSocket build job-2 -f -v -p param_1=p1
test-no-mount:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./
with:
jenkins_home: ''
- run: curl $JENKINS_URL
# Environment variables
- run: test "$JENKINS_HOME" = ""
- run: test -n "$JENKINS_VERSION"
- run: test "$JENKINS_URL" = "http://localhost:8080"
- run: test -n "$COMPOSE_FILE"
# Remote Access API
# https://www.jenkins.io/doc/book/using/remote-access-api/
- run: |
crumb=$(curl -sS -c cookie $JENKINS_URL/crumbIssuer/api/json)
echo "CRUMB_HEADER=$(echo $crumb | jq -r '.crumbRequestField'): $(echo $crumb | jq -r '.crumb')" >> $GITHUB_ENV
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 0
# Jenkins CLI
# https://www.jenkins.io/doc/book/managing/cli/
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket help
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket create-job job-1 < test-resources/jenkins_home/jobs/job-1/config.xml
- run: java -jar jenkins-cli.jar -webSocket create-job job-2 < test-resources/jenkins_home/jobs/job-2/config.xml
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket build job-1 -f -v
- run: java -jar jenkins-cli.jar -webSocket build job-2 -f -v -p param_1=p1
test-jcasc:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- run: mkdir -p $RUNNER_TEMP/jenkins_home/
- run: cp test-resources/jenkins.yaml $RUNNER_TEMP/jenkins_home/
- uses: ./
- run: curl $JENKINS_URL
- run: ls -la $JENKINS_HOME
# Environment variables
- run: test "$JENKINS_HOME" = "$RUNNER_TEMP/jenkins_home"
- run: test -n "$JENKINS_VERSION"
- run: test "$JENKINS_URL" = "http://localhost:8080"
- run: test -n "$COMPOSE_FILE"
# Jenkins container
- run: docker compose exec jenkins printenv
- run: docker compose exec jenkins jenkins-plugin-cli --list
# Remote Access API
- run: |
crumb=$(curl -sS -c cookie $JENKINS_URL/crumbIssuer/api/json)
echo "CRUMB_HEADER=$(echo $crumb | jq -r '.crumbRequestField'): $(echo $crumb | jq -r '.crumb')" >> $GITHUB_ENV
- run: test $(curl -sS -X POST -H "${CRUMB_HEADER}" -b cookie $JENKINS_URL/api/json | jq '.jobs | length') -eq 2
# Jenkins CLI
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket create-job job-jcasc < test-resources/jobs/job-jcasc/config.xml
- run: java -jar jenkins-cli.jar -webSocket build job-jcasc -f -v
test-jcasc-with-secrets:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- run: mkdir -p $RUNNER_TEMP/jenkins_home/
- run: cp test-resources/jenkins.yaml $RUNNER_TEMP/jenkins_home/
- run: echo "SECRET_TEXT=${{ secrets.SECRET_TEXT }}" >> container.env
- uses: ./
with:
env_file: container.env
- run: curl $JENKINS_URL
- run: ls -la $JENKINS_HOME
# Environment variables
- run: test "$JENKINS_HOME" = "$RUNNER_TEMP/jenkins_home"
- run: test -n "$JENKINS_VERSION"
- run: test "$JENKINS_URL" = "http://localhost:8080"
- run: test -n "$COMPOSE_FILE"
# Jenkins container
- run: test "$(docker compose exec jenkins printenv SECRET_TEXT)" = "${{ secrets.SECRET_TEXT }}"
# Jenkins CLI
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket list-jobs
- run: java -jar jenkins-cli.jar -webSocket build job-dsl-plugin-script -f -v
test-plugins:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./
with:
plugins: |
timestamper
git
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: test $(java -jar jenkins-cli.jar -webSocket list-plugins | wc -l) -gt 20
test-no-plugins:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: ./
with:
plugins: ''
- run: wget $JENKINS_URL/jnlpJars/jenkins-cli.jar
- run: java -jar jenkins-cli.jar -webSocket list-plugins
- run: test $(java -jar jenkins-cli.jar -webSocket list-plugins | wc -l) -eq 0
test-passing:
needs: [ test-mount, test-no-mount, test-jcasc, test-jcasc-with-secrets, test-plugins, test-no-plugins ]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- run: echo "All tests have passed."