1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-11-28 08:49:44 +02:00
Commit Graph

41 Commits

Author SHA1 Message Date
Holger Partsch
d4e298464e
Final round of adding quoting to prevent command injection (#5167)
* refactor: use import alias

* fix: add quoting to further shell steps
2024-11-04 14:05:47 +01:00
Alexander Link
500c42860f
Stash via Utils.stash (#4380)
We should use Utils.stash instead of native steps.stash calls (Jenkins)
since important logging is missing.
The default Jenkins stash step does not log any metadata like
stash name, patterns, etc.
2023-07-07 14:35:14 +02:00
Marcus Holl
83519eb771
fix misleading/wrong comment (#4295) 2023-06-01 15:22:57 +02:00
ajrussellsap
029957f98a
Don't unstash the piper binary if it is already present. (#3920)
* Don't unstash the piper binary if it is already present.

* Fixed method name.

* Removed changes to unit test.

* Updated unit tests to account for the check whether the piper binary exists.

* Updated the Maven test to account for the piper binary existance check.

* Updated tests to account for the piper binary existance check.

* Set the shell return value for a test.

* See if it will output the real failure reason.

* Removed code that triggered a different error message if sh(Map) is encountered.

* Added missing constructor parameter.

* Pass the script to the constructor of PiperGoUtils.

* Reverted change to code that is now removed from the master branch.

* Re-instated deleted function.

* Re-add fix to use the correct constructor for PiperGoUtils.
2023-01-16 14:48:16 +05:30
Ashly Mathew
3fb034b629
Fix for checkIfStepActive custom config (#3987)
* Fix for checkIfStepActive custom config

* convert JSONObjects to LinkedHashMap

* fix null pointer

Co-authored-by: Raman Susla<“raman_susla@epam.com”>
2022-08-31 16:11:51 +03:00
Ashly Mathew
b75d6cf9ed
Enable Jenkins to use checkIfStepActive go step (#3931)
* Extend checkIfStepActive

* adapt default format in abap Tests
Co-authored-by: dominiklendle <d.lendle@sap.com>
Co-authored-by: “Raman <“raman_susla@epam.com”>
2022-08-29 11:39:08 +02:00
Linda Siebert
acbcc5646b
[ANS] Change helper and re-generate steps (#3675)
* Add ans implementation

* Remove todo comment

* Rename test function

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

* Better wording

Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

* Add reading of response body function

* Use http pkg ReadResponseBody

* Check read error

* Better test case description

* Fix formatting

* Create own package for read response body

* Omit empty nested resource struct

* Separate Resource struct from Event struct

* Merge and unmarshall instead of only unmarshalling

* Improve status code error message

* Remove unchangeable event fields

* Separate event parts

* Change log level setter function

* Restructure ans send test

* Revert exporting readResponseBody function

Instead the code is duplicated in the xsuaa and ans package

* Add check correct ans setup request

* Add set options function for mocking

* Review fixes

* Correct function name

* Use strict unmarshalling

* Validate event

* Move functions

* Add documentation comments

* improve test

* Validate event

* Add logrus hook for ans

* Set defaults on new hook creation

* Fix log level on error

* Don't alter entry log level

* Set severity fatal on 'fatal error' log message

* Ensure that log entries don't affect each other

* Remove unnecessary correlationID

* Use file path instead of event template string

* Improve warning messages

* Add empty log message check

* Allow configuration from file and string

* Add sourceEventId to tags

* Change resourceType to Pipeline

* Use structured config approach

* Use new log level set function

* Check correct setup and return error

* Mock http requests

* Only send log level warning or higher

* Use new function name

* One-liner ifs

* Improve test name

* Fix tests

* Prevent double firing

* Reduce Fire test size

* Add error message to test

* Reduce newANSHook test size

* Further check error

* Rename to defaultEvent in hook struct

* Reduce ifs further

* Fix set error category test

The ansHook Fire test cannot run in parallel, as it would affect the
other tests that use the error category.

* Change function name to SetServiceKey

* Validate event

* Rename to eventTemplate in hook struct

* Move copy to event.go

* Fix function mix

* Remove unnecessary cleanup

* Remove parallel test

The translation fails now and again when parallel is on.

* Remove prefix test

* Remove unused copyEvent function

* Fix ifs

* Add docu comment

* Register ans hook from pkg

* register hook and setup event template seperately

* Exclusively read eventTemplate from environment

* setupEventTemplate tests

* adjust hook levels test

* sync tests- wlill still fail

* migrate TestANSHook_registerANSHook test

* fixes

* Introduce necessary parameters

* Setup hook test

* Use file instead

* Adapt helper for ans

* Generate go files

* Add ans config to general config

* Change generator

* Regenerate steps

* Allow hook config from user config

Merges with hook config from defaults

* Remove ans flags from root command

* Get environment variables

* Generate files

* Add test when calling merge twice

* Update generator

* Regenerate steps

* Check two location for ans service key env var

* Re-generate

* Fix if

* Generate files with fix

* Duplicate config struct

* Add type casting test for ans config

* Fix helper

* Fix format

* Fix type casting of config

* Revert "Allow hook config from user config"

This reverts commit 4864499a4c497998c9ffc3e157ef491be955e68e.

* Revert "Add test when calling merge twice"

This reverts commit b82320fd07b82f5a597c5071049d918bcf62de00.

* Add ans config tests

* Improve helper code

* Re-generate commands

* Fix helper unit tests

* Change to only one argument

* Fix helper tests

* Re-generate

* Revert piper and config changes

* Re-generate missing step

* Generate new steps

* [ANS] Add servicekey credential to environment (#3684)

* Add ANS credential

* Switch to hooks and remove comments

* Add subsection for ans

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* Remove changes to piper.go

* Remove formatting

* Add test for ANS

* Define hook credential seperately from step credential

* Add test for retrieval from general section

* Add comment

* Get ans hook info from DefaultValueCache

* [ANS] Add documentation (#3704)

* Add ANS credential

* Switch to hooks and remove comments

* Add subsection for ans

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* Remove changes to piper.go

* Remove formatting

* Add test for ANS

* Define hook credential seperately from step credential

* Add test for retrieval from general section

* Add comment

* Add documentation

* Review changes

* Review comments

* Improve documentation further

* Add note of two event templates

* Add log level destinction

* Further improvements

* Improve text

* Remove unused things

* Add ANS credential

* Switch to hooks and remove comments

* Add subsection for ans

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* Remove changes to piper.go

* Remove formatting

* Add test for ANS

* Define hook credential seperately from step credential

* Add test for retrieval from general section

* Add comment

* Get ans hook info from DefaultValueCache

* Improvements

Co-authored-by: Linda Siebert <linda.siebert@sap.com>
Co-authored-by: Linda Siebert <39100394+LindaSieb@users.noreply.github.com>

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>

* New lines

Co-authored-by: Oliver Feldmann <oliver.feldmann@sap.com>
Co-authored-by: Roland Stengel <r.stengel@sap.com>
Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2022-06-22 13:31:17 +02:00
Kevin Stiehl
d1c8abc6b3
refactor: move common pipeline environment handling to golang (#2823)
* make use of new read,writePipelineEnv Steps in groovy

* remove unused cat

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-06-15 14:34:56 +02:00
Oliver Nocon
d04a7c2eb3
feat(pipelineCreateScanSummary) Create groovy wrapper (#2743)
* feat(pipelineCreateScanSummary) Create groovy wrapper

* add command to binary

* stash step reports

* update stash

* fix typo

* unstash reports first

* update reporting

* update json reporting

* update tests & enhance logging

* update md report

* update md reporting

* fix rendering

* update tests
2021-04-15 07:45:06 +02:00
Christopher Fenner
be68270cb4
fix(piperExecuteBin): move CPE.readFromDisk to own finally block (#1885)
* Update piperExecuteBin.groovy

fixes #1881

* Update piperExecuteBin.groovy
2021-03-12 09:42:19 +01:00
Christopher Fenner
f999925788
fix(influx): correct data type of influx measurements (#2171)
* update data type of influx measurements

* Update checkmarx.yaml

* pick changes from #1885 for testing

* update generated code

* update to new datatype

* adjust to type changes

* change back to string type

* Update fortifyExecuteScan.go

* add typo to be backward compatible

* change type to int for files_scanned and lines_of_code_scanned

* add typo

* add measurements to whitesource

* update generated sources

* adjust test cases

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2021-03-10 16:00:53 +01:00
Kevin Stiehl
ffffe8295e
(Vault) Improvements (#2439)
* vault improvements

* Update cloudFoundryDeploy.yaml

remove double PARAMETERS

* go generate

* fix type & resturcutre paragraph to a list

* remove non-existent secrets

* build trigger

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2021-02-15 09:48:51 +01:00
Oliver Nocon
006aaab50d
fix(handlePipelineStepError): correct handling of failed steps (#2498)
* WIP: debug incorrect error message

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update handlePipelineStepErrors.groovy

* Update piperExecuteBin.groovy

* Update handlePipelineStepErrors.groovy

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update commonPipelineEnvironment.groovy

* Update piperExecuteBin.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update piperExecuteBin.groovy

* Update commonPipelineEnvironment.groovy

* Update handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Update piperExecuteBin.groovy

* Update vars/piperExecuteBin.groovy

* Update vars/handlePipelineStepErrors.groovy

* Update handlePipelineStepErrors.groovy

* Apply suggestions from code review

* correct test case

* change test case

Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
Co-authored-by: Christopher Fenner <Christopher.Fenner@sap.com>
2021-01-11 10:49:33 +01:00
Oliver Nocon
5f5450449e
fix(piperExecuteBin): define variable (#2497) 2021-01-07 12:24:48 +01:00
Marcus Holl
17bdbe2ef4
piperExecuteBin: provide credentials directly without indirection into config (#2437)
`piperExecuteBin` is called with a credentials list. Each list entry is a map consisting of
* the type of the credential (e.g. usernamePassword, token)
* the identifier which is used for resolving the credential.
* a list of environment variables which holds the resolved credentials.

Inside `piperExecuteBin` the id was resolved against the config and the result was used for resolving the credentials against the jenkins-credentials-plugin.

With this change here we introduce another key for the map mentioned above:
* resolveCredentialsId

When this key is provided with value `false` we do not resolve the credentials-id from the config. In that case the id is directly used for resolving the credential again the jenkins-credentials-plugin.
2020-12-07 08:54:49 +01:00
Kevin Stiehl
3eae0c5f68
feat(vault): fetch secrets from vault (#2032)
* cloud-foundry & sonar from vault

* add vault development hint

* don't abort on vault errors

* cloudfoundry make credentialsId only mandatory when vault is not configured

* add vault ref to step ymls

* rename vaultAddress to vaultServerUrl

* rename PIPER_vaultRole* to PIPER_vaultAppRole*

* add resourceRef for detect step

* fix error when no namespace is set

* added debug logs

* added debug logs

* fix vault resolving

* add vaultCustomBasePath

* rename vault_test.go to client_test.go

* refactored vault logging

* refactored config param lookup for vault

* added tüddelchen

* rename vaultCustomBasePath to vaultPath

* fix tests

* change lookup path for group secrets

* fix interpolation tests

* added vault resource ref to versioning

* execute go generate

* rename Approle to AppRole

* change verbose back to false

Co-authored-by: Leander Schulz <leander.schulz01@sap.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-10-13 14:14:47 +02:00
Marcus Holl
75a35fb35a
Improve logging wrt the docker image used for launching piper-go (#1578)
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-10-01 16:27:50 +02:00
Christopher Fenner
896519a77f
refactor(sonar): reuse piperExecuteBin code (#1880)
* reuse piperExecuteBin code

* add correlation id

* reuse credential loading

* reuse dockerWrapper

* rearrange code

* add influx wrapper

* correct writeToDisk position
2020-08-06 14:22:40 +02:00
Christopher Fenner
2e56b194aa
fix(step results): publish step results also on step error (#1882) 2020-08-05 13:20:29 +02:00
Stephan Aßmus
a61798ccbf
New step mavenExecuteIntegration (#1829)
Co-authored-by: Florian Wilhelm <florian.wilhelm02@sap.com>
2020-07-29 19:51:27 +02:00
Oliver Nocon
520f2cc975
Fix stashing of piper binary (#1764)
* Update piperExecuteBin.groovy

* update tests
2020-07-06 13:22:36 +02:00
Oliver Nocon
49b7abb4ca
Fix stashing issue with binrary execution (#1749)
Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-07-02 12:08:56 +02:00
Stephan Aßmus
dc99676c8d
Init container map via YAML resource (#1695) 2020-06-24 17:04:58 +02:00
Stephan Aßmus
56699ab019
Run artifactPrepareVersion in maven container if necessary (#1634)
* The metadata for artifactPrepareVersion-go specifies a container for when the buildTool is maven.
* The alias to 'mavenExecute' was removed. The problem with this is that when a section containers is included in the metadata, dockerImage will always be picked up from mavenExecute, the conditional dependency on buildTool will not even be considered. Parameters such as m2Path, projectSettingsFile and globalSettingsFile should be configured in general/maven if necessary.
* When the step ends up being executed within dockerExecuteOnKubernetes, we need to preserve the .git folder. This folder would normally be excluded by the default excludes of the stash step. There was already a comment that suppressing this behavior by passing useDefaultExcludes: false was problematic (unfortunately without going into details), so I've added a new parameter to dockerExecute and dockerExecuteOnKubernetes named stashNoDefaultExcludes (note the reverted meaning to ease preserving the default behavior when this parameter is not provided). This parameter is passed to piperExecuteBin from the artifactPreferVersion groovy wrapper.
2020-06-08 17:08:05 +02:00
Oliver Nocon
d5d510719d
piperExecuteBin - prevent non-speaking exit code 1 error (#1584)
* piperExecuteBin - prevent non-speaking exit code 1 error

Make sure that error during context resolution gets more context.

* properly provide golang errors

* improve error message, when no details are available

* Add error category

* Update getConfig.go
2020-05-26 07:58:03 +02:00
Oliver Nocon
09b2ddbafa
piperExecuteBin: allow easier re-use (#1566)
* piperExecuteBin: allow easier re-use
* make binary path configurable in groovy step using `piperExecuteBin`
2020-05-19 16:49:21 +02:00
Stephan Aßmus
5ab4dedcb2
Optionally ignore custom defaults (#1538)
* Add parameter "--ignoreCustomDefaults"
* Pass to piper customDefaults from config also via --defaultConfig
... and add "--ignoreCustomDefaults".
* Log output when ignoring customDefaults

Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-05-14 10:50:58 +02:00
Florian Wilhelm
eaf5479e9c
Fix maven parameter handling (#1493)
Avoid maven error `Unknown lifecycle phase \"-\"` when the value of a define contains `-`.

Don't split and trim maven arguments. Expect they come in as a list, keep them as list.

This is a breaking change compared to the old Groovy implementation which relied on using a shell for calling maven.

As an example, consider this diff:

```diff
-        goals: 'org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate',
-        defines: "-Dexpression=$pomPathExpression -DforceStdout -q",
+        goals: ['org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate'],
+        defines: ["-Dexpression=$pomPathExpression", "-DforceStdout", "-q"],
```
2020-05-06 17:43:32 +02:00
Christopher Fenner
669dc91688
fix: prevent script to json conversion (#1495)
* prevent script to json conversion

* use piperExecuteBin

* correct imports

* fix trailing spaces
2020-05-05 15:21:59 +02:00
Christopher Fenner
d75dced2a6
test: activate common test cases using piperExecuteBin (#1501) 2020-05-05 14:31:12 +02:00
Oliver Nocon
3f1a9d004a
Allow proper usage of resilience feature in golang steps (#1487)
* Allow proper usage of resilience feature in golang steps
2020-04-30 10:39:27 +02:00
Oliver Nocon
e8c6baca42
Golang errors: improve error message in groovy part (#1482)
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-04-29 11:26:29 +02:00
Oliver Nocon
43947e6ef5
Pass golang error details to Jenkins pipeline (#1443)
Do not exit with os.Exit(1) but using log.Entry().Fatal() instead
* Golang: forward error details
* extend groovy wrapper to provide proper error message
* create closure for error handling
2020-04-28 07:42:02 +02:00
Oliver Nocon
b9450702af
piperExecuteBin: fix reading environment (#1452)
* piperExecuteBin: fix reading environment
* update tests

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
2020-04-24 22:41:34 +02:00
Daniel Kurzynski
974327d16e
Use mavenExecute from go (#1388)
Also establish mavenExecute() via new JenkinsMavenExecuteRule in Groovy Unit Tests.

Co-authored-by: Stephan Aßmus <stephan.assmus@sap.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2020-04-24 10:41:49 +02:00
Oliver Nocon
999197b919
Add step to prepare the version for an artifact (#1343) 2020-04-03 16:34:40 +02:00
Stephan Aßmus
0b8b6f2b0c
Migrate stage artifact deployment from Cloud SDK Pipeline-Lib (#1324)
Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
Co-authored-by: Florian Geckeler <f.geckeler@sap.com>
2020-03-31 15:16:18 +02:00
Stephan Aßmus
0c6dabbd1e
Pass custom config and default configs also to getConfig (#1346)
Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-03-31 13:10:02 +02:00
Stephan Aßmus
03096b5d05
Pass custom default-config files and custom project config from Jenkins side to piper (#1333) 2020-03-30 14:31:24 +02:00
Stephan Aßmus
20b65d5a2e
Implement nexusUpload command and tests (#1255)
Artifacts to upload are assembled for MTA projects and Maven projects with optional application sub-module. Then maven deploy:deploy-file is used as backend to upload bundles of artifacts plus sub-artifacts.

Co-authored-by: Florian Wilhelm <florian.wilhelm02@sap.com>
2020-03-20 18:20:52 +01:00
Oliver Nocon
a49d8947c0
Streamline calling piper go binary (#1254) 2020-03-17 09:19:09 +01:00