mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-28 05:47:08 +02:00
testing piper forks (#3420)
* developer doku update on how to test with forked repos Co-authored-by: rosemarieB <45030247+rosemarieB@users.noreply.github.com>
This commit is contained in:
parent
30aa6eea7d
commit
3799199dc6
@ -478,6 +478,78 @@ func TestMethod(t *testing.T) {
|
||||
}
|
||||
```
|
||||
|
||||
### Test pipeline for your fork (Jenkins)
|
||||
|
||||
Piper is ececuting the steps of each stage within a container. If you want to test your developments you have to ensure they are part of the image which is used in your test pipeline.
|
||||
|
||||
#### Testing Pipeline or Stage Definition changes (Jenkins)
|
||||
|
||||
As the pipeline and stage definitions (e.g. \*Pipeline\*Stage\*.groovy files in the vars folder) are directly executed you can easily test them just by referencing to your repo/branch/tag in the jenkinsfile.
|
||||
|
||||
```groovy
|
||||
@Library('my-piper-lib-os-fork@MyTest') _
|
||||
|
||||
abapEnvironmentPipeline script: this
|
||||
```
|
||||
|
||||
#### Testing changes on Step Level (Jenkins)
|
||||
|
||||
To trigger the creation of a "custom" container with your changes you can reuse a feature in piper which is originally meant for executing the integration tests. If the environment variables 'REPOSITORY_UNDER_TEST' (pointing to your forked repo) and 'LIBRARY_VERSION_UNDER_TEST' (pointing to a tag in your forked repo) are set a corresponding container gets created on the fly upon first usage in the pipeline. The drawback is that this takes extra time (1-2 minutes) you have to spend for every execution of the pipeline.
|
||||
|
||||
```groovy
|
||||
@Library('piper-lib-os') _
|
||||
|
||||
env.REPOSITORY_UNDER_TEST = 'myfork' // e.g. 'myUser/jenkins-library'
|
||||
env.LIBRARY_VERSION_UNDER_TEST = 'MyTag'
|
||||
|
||||
abapEnvironmentPipeline script: this
|
||||
```
|
||||
|
||||
#### Using Parameterized Pipelines (Jenkins)
|
||||
|
||||
For test purpose it can be useful to utilize a parameterized pipeline. E.g. to toggle creation of the custom container:
|
||||
|
||||
```groovy
|
||||
@Library('my-piper-lib-os-fork@MyTest') _
|
||||
|
||||
properties([
|
||||
parameters([
|
||||
booleanParam(name: 'toggleSomething', defaultValue: false, description: 'dito'),
|
||||
booleanParam(name: 'testPiperFork', defaultValue: false, description: 'dito'),
|
||||
string(name: 'repoUnderTest', defaultValue: '<MyUser>/jenkins-library', description: 'dito'),
|
||||
string(name: 'tag', defaultValue: 'MyTest', description: 'dito')
|
||||
])
|
||||
])
|
||||
|
||||
if (params.testPiperFork == true) {
|
||||
env.REPOSITORY_UNDER_TEST = params.repoUnderTest
|
||||
env.LIBRARY_VERSION_UNDER_TEST = params.tag
|
||||
}
|
||||
|
||||
abapEnvironmentPipeline script: this
|
||||
```
|
||||
|
||||
or skipping steps/stages with the help of extensions:
|
||||
|
||||
```groovy
|
||||
void call(Map piperParams) {
|
||||
echo "Start - Extension for stage: ${piperParams.stageName}"
|
||||
|
||||
if (params.toggleSomething == true) {
|
||||
// do something
|
||||
echo "now execute original stage as defined in the template"
|
||||
piperParams.originalStage()
|
||||
} else {
|
||||
// do something else
|
||||
// e.g. only this singele step of the stage
|
||||
somePiperStep( script: piperParams.script, someConfigParameter: '<...>' )
|
||||
}
|
||||
|
||||
echo "End - Extension for stage: ${piperParams.stageName}"
|
||||
}
|
||||
return this
|
||||
```
|
||||
|
||||
## Debugging
|
||||
|
||||
Debugging can be initiated with VS code fairly easily. Compile the binary with specific compiler flags to turn off optimizations `go build -gcflags "all=-N -l" -o piper.exe`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user