File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -217,6 +217,40 @@ Please refer to the `BasePipelineTest` class for the list of currently supported
217217Some tricky methods such as ` load ` and ` parallel ` are implemented directly in the helper.
218218If you want to override those, make sure that you extend the ` PipelineTestHelper ` class.
219219
220+ ### Mocking Jenkins Credentials
221+
222+ You can create mock credentials for use in the pipeline.
223+ The provided mock methods can be used to simulate sensitive data, such as access keys or user login details.
224+
225+ ``` groovy
226+ // Jenkinsfile
227+ node {
228+ stage('Process with credentials') {
229+ withCredentials([usernamePassword(credentialsId: 'credentials-1', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
230+ echo 'User/Password: ${USERNAME}/${PASSWORD}'
231+ }
232+ withCredentials([string(credentialsId: 'credentials-2', variable: 'TOKEN')]) {
233+ echo 'Token: ${TOKEN}'
234+ }
235+ }
236+ }
237+ ```
238+
239+ ``` groovy
240+ import com.lesfurets.jenkins.unit.BasePipelineTest
241+
242+ class TestExampleJob extends BasePipelineTest {
243+ @Test
244+ void exampleWithCredentialsTest() {
245+ // Simulates a username and password
246+ addUsernamePasswordCredential('credentials-1', 'admin', 'very-strong-password')
247+
248+ // Simulates a secret text
249+ addStringCredential('credentials-2', 'secret-token')
250+ }
251+ }
252+ ```
253+
220254### Mocking ` readFile ` and ` fileExists `
221255
222256The ` readFile ` and ` fileExists ` steps can be mocked to return a specific result for a
You can’t perform that action at this time.
0 commit comments