Skip to content

Commit 7b476a1

Browse files
author
Reinhold Füreder
committed
Add test for scripted pipeline job with "parameters" (job property) and "withCredentials" step
1 parent 36b2d1c commit 7b476a1

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lesfurets.jenkins
2+
3+
import com.lesfurets.jenkins.unit.BaseRegressionTest
4+
import org.junit.Before
5+
import org.junit.Test
6+
7+
class TestWithCredentialsAndParametersJob extends BaseRegressionTest {
8+
9+
@Override
10+
@Before
11+
void setUp() throws Exception {
12+
scriptRoots += 'src/test/jenkins'
13+
super.setUp()
14+
}
15+
16+
@Test
17+
void should_run_script_with_parameters() {
18+
// when:
19+
runScript("job/withCredentialsAndParameters.jenkins")
20+
21+
// then:
22+
assertJobStatusSuccess()
23+
testNonRegression("withCredentialsAndParameters")
24+
}
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
properties([
2+
parameters([
3+
booleanParam(name: 'myBooleanParam', description: 'My boolean typed parameter'),
4+
string(name: 'myStringParam', defaultValue: 'my default value', description: 'My string typed parameter')
5+
])
6+
])
7+
8+
echo("'myStringParam' value is default: ${params.myStringParam}")
9+
10+
withCredentials([string(credentialsId: 'my-gitlab-api-token', variable: 'GITLAB_API_TOKEN')]) {
11+
echo("'my-gitlab-api-token' credential variable value: ${GITLAB_API_TOKEN}")
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
withCredentialsAndParameters.run()
2+
withCredentialsAndParameters.booleanParam({name=myBooleanParam, description=My boolean typed parameter})
3+
withCredentialsAndParameters.string({name=myStringParam, defaultValue=my default value, description=My string typed parameter})
4+
withCredentialsAndParameters.parameters([null, null])
5+
withCredentialsAndParameters.properties([null])
6+
withCredentialsAndParameters.echo('myStringParam' value is default: my default value)
7+
withCredentialsAndParameters.string({credentialsId=my-gitlab-api-token, variable=GITLAB_API_TOKEN})
8+
withCredentialsAndParameters.withCredentials([GITLAB_API_TOKEN], groovy.lang.Closure)
9+
withCredentialsAndParameters.echo('my-gitlab-api-token' credential variable value: GITLAB_API_TOKEN)

0 commit comments

Comments
 (0)