1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-07-15 01:34:38 +02:00

fix code climate issues II (#715)

* fix code climate issues

* fix code climate issues

* fix code climate issues
This commit is contained in:
Christopher Fenner
2019-05-17 13:20:13 +02:00
committed by Marcus Holl
parent cf08f3c7c8
commit 41ee87d147
15 changed files with 69 additions and 64 deletions

View File

@ -71,8 +71,7 @@ To setup the shared library, you need to perform the following steps:
1. Login to your Jenkins instance with administration privileges. 1. Login to your Jenkins instance with administration privileges.
1. Open the system configuration page (*Manage Jenkins > Configure System*). 1. Open the system configuration page (*Manage Jenkins > Configure System*).
1. Scroll down to section *Global Pipeline Libraries* and add a new Library by 1. Scroll down to section *Global Pipeline Libraries* and add a new Library by clicking the *Add* button.
clicking the *Add* button.
1. set *Library Name* to `piper-lib-os` 1. set *Library Name* to `piper-lib-os`
1. set *Default Version* to the branch or tag you want to consume (e.g. `master` or `v0.1`) 1. set *Default Version* to the branch or tag you want to consume (e.g. `master` or `v0.1`)
1. set *Retrieval Method* to `Modern SCM` 1. set *Retrieval Method* to `Modern SCM`
@ -102,6 +101,7 @@ Feel free to open new issues for feature requests, bugs or general feedback on
the [GitHub issues page of this project][piper-library-issues]. the [GitHub issues page of this project][piper-library-issues].
Register to our [google group][google-group] in order to get updates or for asking questions. Register to our [google group][google-group] in order to get updates or for asking questions.
# Contributing # Contributing
Read and understand our [contribution guidelines][piper-library-contribution] Read and understand our [contribution guidelines][piper-library-contribution]

View File

@ -11,10 +11,10 @@ Your configuration inherits from the default configuration located at [https://g
Configuration of the Piper steps as well the Piper templates can be done in a hierarchical manner. Configuration of the Piper steps as well the Piper templates can be done in a hierarchical manner.
1. Directly passed step parameters will always take precedence over other configuration values and defaults 1. Directly passed step parameters will always take precedence over other configuration values and defaults
2. Stage configuration parameters define a Jenkins pipeline stage dependent set of parameters (e.g. deployment options for the `Acceptance` stage) 1. Stage configuration parameters define a Jenkins pipeline stage dependent set of parameters (e.g. deployment options for the `Acceptance` stage)
3. Step configuration defines how steps behave in general (e.g. step `cloudFoundryDeploy`) 1. Step configuration defines how steps behave in general (e.g. step `cloudFoundryDeploy`)
4. General configuration parameters define parameters which are available across step boundaries 1. General configuration parameters define parameters which are available across step boundaries
5. Default configuration comes with the Piper library and is always available 1. Default configuration comes with the Piper library and is always available
![Piper Configuration](images/piper_config.png) ![Piper Configuration](images/piper_config.png)

View File

@ -33,10 +33,10 @@ The basic workflow is as follows:
**Note:** The blank line between message header and message description is mandatory. **Note:** The blank line between message header and message description is mandatory.
2. To communicate with SAP Solution Manager, the pipeline uses credentials that must be stored on Jenkins using the credential ID `CM`. For more information, see [checkChangeInDevelopment](https://sap.github.io/jenkins-library/steps/checkChangeInDevelopment/). 1. To communicate with SAP Solution Manager, the pipeline uses credentials that must be stored on Jenkins using the credential ID `CM`. For more information, see [checkChangeInDevelopment](https://sap.github.io/jenkins-library/steps/checkChangeInDevelopment/).
3. The required transport request is created on the fly. **Note:** The change document can contain various components (for example, UI and backend components). 1. The required transport request is created on the fly. **Note:** The change document can contain various components (for example, UI and backend components).
4. The changes of your development team trigger the Jenkins pipeline. It builds and validates the changes and attaches them to the respective transport request. 1. The changes of your development team trigger the Jenkins pipeline. It builds and validates the changes and attaches them to the respective transport request.
5. As soon as the development process is completed, the change document in SAP Solution Manager can be set to status `to be tested` and all components can be transported to the test system. 1. As soon as the development process is completed, the change document in SAP Solution Manager can be set to status `to be tested` and all components can be transported to the test system.
![Hybrid Application Development Workflow](../images/Scenario_SolMan.png "Hybrid Application Development Workflow") ![Hybrid Application Development Workflow](../images/Scenario_SolMan.png "Hybrid Application Development Workflow")
###### Hybrid Application Development Workflow ###### Hybrid Application Development Workflow

View File

@ -32,8 +32,7 @@ resource in an custom shared library.
// inside the shared lib denoted by 'foo' the additional configuration file // inside the shared lib denoted by 'foo' the additional configuration file
// needs to be located under 'resources' ('resoures/myConfig.yml') // needs to be located under 'resources' ('resoures/myConfig.yml')
prepareDefaultValues script: this, prepareDefaultValues script: this, customDefaults: 'myConfig.yml'
customDefaults: 'myConfig.yml'
``` ```
Example content of `'resources/myConfig.yml'` in branch `'master'` of the repository denoted by Example content of `'resources/myConfig.yml'` in branch `'master'` of the repository denoted by
@ -79,11 +78,13 @@ The parameters can also be provided when the step is invoked:
// explict endpoint provided, we search for changeDocumentId // explict endpoint provided, we search for changeDocumentId
// starting at the previous commit (HEAD~1) rather than on // starting at the previous commit (HEAD~1) rather than on
// 'origin/master' (the default). // 'origin/master' (the default).
checkChangeInDevelopment script:this checkChangeInDevelopment(
changeManagement: [ script: this
endpoint: 'https:example.org/cm' changeManagement: [
git: [ endpoint: 'https:example.org/cm'
from: 'HEAD~1' git: [
] from: 'HEAD~1'
] ]
]
)
``` ```

View File

@ -43,7 +43,7 @@ Once you have started both docker containers and Influx and Grafana are running
To setup your Jenkins you need to do two configuration steps: To setup your Jenkins you need to do two configuration steps:
1. Configure Jenkins (via Manage Jenkins) 1. Configure Jenkins (via Manage Jenkins)
2. Adapt pipeline configuration 1. Adapt pipeline configuration
### Configure Jenkins ### Configure Jenkins

View File

@ -10,7 +10,7 @@ Kaniko expects a Docker `config.json` file containing the credential information
You can create it like explained in the Docker Success Center in the articale about [How to generate a new auth in the config.json file](https://success.docker.com/article/generate-new-auth-in-config-json-file). You can create it like explained in the Docker Success Center in the articale about [How to generate a new auth in the config.json file](https://success.docker.com/article/generate-new-auth-in-config-json-file).
Please copy this file and upload it to your Jenkins for example<br /> Please copy this file and upload it to your Jenkins for example<br />
via _Jenkins_ -> _Credentials_ -> _System_ -> _Global credentials (unrestricted)_ -> _ Add Credentials_ -> via _Jenkins_ -> _Credentials_ -> _System_ -> _Global credentials (unrestricted)_ -> _Add Credentials_ ->
* Kind: _Secret file_ * Kind: _Secret file_
* File: upload your `config.json` file * File: upload your `config.json` file

View File

@ -23,8 +23,7 @@ resource in an custom shared library.
// inside the shared lib denoted by 'foo' the additional configuration file // inside the shared lib denoted by 'foo' the additional configuration file
// needs to be located under 'resources' ('resoures/myConfig.yml') // needs to be located under 'resources' ('resoures/myConfig.yml')
prepareDefaultValues script: this, prepareDefaultValues script: this, customDefaults: 'myConfig.yml'
customDefaults: 'myConfig.yml'
``` ```
Example content of `'resources/myConfig.yml'` in branch `'master'` of the repository denoted by Example content of `'resources/myConfig.yml'` in branch `'master'` of the repository denoted by

View File

@ -74,21 +74,25 @@ The parameters can also be provided when the step is invoked. For examples see b
```groovy ```groovy
// SOLMAN // SOLMAN
transportRequestUploadFile script:this, transportRequestUploadFile(
changeDocumentId: '001', // typically provided via git commit history script: this,
transportRequestId: '001', // typically provided via git commit history changeDocumentId: '001', // typically provided via git commit history
applicationId: '001', transportRequestId: '001', // typically provided via git commit history
filePath: '/path', applicationId: '001',
changeManagement:[ filePath: '/path',
type: 'SOLMAN' changeManagement: [
endpoint: 'https://example.org/cm' type: 'SOLMAN'
] endpoint: 'https://example.org/cm'
]
)
// CTS // CTS
transportRequestUploadFile script:this, transportRequestUploadFile(
transportRequestId: '001', // typically provided via git commit history script: this,
filePath: '/path', transportRequestId: '001', // typically provided via git commit history
changeManagement:[ filePath: '/path',
type: 'CTS' changeManagement: [
endpoint: 'https://example.org/cm' type: 'CTS'
] endpoint: 'https://example.org/cm'
]
)
``` ```

View File

@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<groupId>org.jenkins-ci.plugins</groupId> <groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId> <artifactId>plugin</artifactId>

View File

@ -37,4 +37,3 @@ class MtaUtils {
if (!script.fileExists(targetMtaDescriptor)) throw new AbortException("'${targetMtaDescriptor}' has not been generated.") if (!script.fileExists(targetMtaDescriptor)) throw new AbortException("'${targetMtaDescriptor}' has not been generated.")
} }
} }

View File

@ -421,16 +421,16 @@ public class ChangeManagement implements Serializable {
String clientOpts = '') { String clientOpts = '') {
String cmCommandLine = '#!/bin/bash' String cmCommandLine = '#!/bin/bash'
if(clientOpts) { if(clientOpts) {
cmCommandLine += """ cmCommandLine += """
export CMCLIENT_OPTS="${clientOpts}" """ export CMCLIENT_OPTS="${clientOpts}" """
} }
cmCommandLine += """ cmCommandLine += """
cmclient -e '$endpoint' \ cmclient -e '$endpoint' \
-u '$username' \ -u '$username' \
-p '$password' \ -p '$password' \
-t ${type} \ -t ${type} \
${command} ${(args as Iterable).join(' ')} ${command} ${(args as Iterable).join(' ')}
""" """
return cmCommandLine return cmCommandLine
} }
} }

View File

@ -23,7 +23,7 @@ public class StepHelpers {
} }
script.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + script.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
" Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
try { try {
transportRequestId = cm.getTransportRequestId( transportRequestId = cm.getTransportRequestId(
@ -62,7 +62,7 @@ public class StepHelpers {
} }
script.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + script.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." +
"Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." "Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'."
try { try {
changeDocumentId = cm.getChangeDocumentId( changeDocumentId = cm.getChangeDocumentId(
@ -91,15 +91,15 @@ public class StepHelpers {
backendType = configuration.changeManagement.type as BackendType backendType = configuration.changeManagement.type as BackendType
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
script.error "Invalid backend type: '${configuration.changeManagement.type}'. " + script.error "Invalid backend type: '${configuration.changeManagement.type}'. " +
"Valid values: [${BackendType.values().join(', ')}]. " + "Valid values: [${BackendType.values().join(', ')}]. " +
"Configuration: 'changeManagement/type'." "Configuration: 'changeManagement/type'."
} }
if (backendType == BackendType.NONE) { if (backendType == BackendType.NONE) {
script.echo "[INFO] Change management integration intentionally switched off. " + script.echo "[INFO] Change management integration intentionally switched off. " +
"In order to enable it provide 'changeManagement/type with one of " + "In order to enable it provide 'changeManagement/type with one of " +
"[${BackendType.values().minus(BackendType.NONE).join(', ')}] and maintain " + "[${BackendType.values().minus(BackendType.NONE).join(', ')}] and maintain " +
"other required properties like 'endpoint', 'credentialsId'." "other required properties like 'endpoint', 'credentialsId'."
} }
return backendType return backendType

View File

@ -169,9 +169,9 @@ void call(Map parameters = [:], Closure body = null) {
try { try {
sh """#!/bin/bash sh """#!/bin/bash
git add . git add .
git ${gitConfig} commit -m 'update version ${newVersion}' git ${gitConfig} commit -m 'update version ${newVersion}'
git tag ${config.tagPrefix}${newVersion}""" git tag ${config.tagPrefix}${newVersion}"""
config.gitCommitId = gitUtils.getGitCommitIdOrNull() config.gitCommitId = gitUtils.getGitCommitIdOrNull()
} catch (e) { } catch (e) {
error "[${STEP_NAME}]git commit and tag failed: ${e}" error "[${STEP_NAME}]git commit and tag failed: ${e}"

View File

@ -177,9 +177,9 @@ void call(parameters = [:]) {
"Change document id not provided (parameter: \'changeDocumentId\' or via commit history).") "Change document id not provided (parameter: \'changeDocumentId\' or via commit history).")
} }
configuration = configHelper configuration = configHelper
.withMandatoryProperty('transportRequestId', .withMandatoryProperty('transportRequestId',
"Transport request id not provided (parameter: \'transportRequestId\' or via commit history).") "Transport request id not provided (parameter: \'transportRequestId\' or via commit history).")
.use() .use()
def uploadingMessage = ['[INFO] Uploading file ' + def uploadingMessage = ['[INFO] Uploading file ' +
"'${backendType == BackendType.RFC ? configuration.applicationUrl : configuration.filePath}' " + "'${backendType == BackendType.RFC ? configuration.applicationUrl : configuration.filePath}' " +