1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Merge pull request #4 from SAP/master

get changes from master
This commit is contained in:
Christopher Fenner 2018-04-05 09:06:09 +02:00 committed by GitHub
commit b08d26f5fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 1773 additions and 1610 deletions

View File

@ -4,13 +4,27 @@ install:
- pip install --user mkdocs mkdocs-material
script:
- mvn test -B
- if [[ "${TRAVIS_PULL_REQUEST}" != "false" ]]; then cd documentation && mkdocs build --clean --verbose --strict && cd ..; fi;
- |
if [[ "${TRAVIS_PULL_REQUEST}" != "false" ]]
then
cd documentation && mkdocs build --clean --verbose --strict && cd ..
else
# Only in case we are in master branch of the leading SAP repo we would like to deploy,
# not from the forks.
if [[ "${TRAVIS_BRANCH}" == "master" && "${TRAVIS_REPO_SLUG}" == "SAP/jenkins-library" ]]
then
openssl aes-256-cbc -K $encrypted_12c8071d2874_key -iv $encrypted_12c8071d2874_iv -in cfg/id_rsa.enc -out cfg/id_rsa -d
./gh-pages-deploy.sh
else
echo "Publishing documentation skipped."
fi
fi
cache:
directories:
- $HOME/.m2
- $HOME/.cache/pip
after_success:
- mvn -DrepoToken=$COVERALLS_REPO_TOKEN org.jacoco:jacoco-maven-plugin:report org.eluder.coveralls:coveralls-maven-plugin:report
notifications:
slack:
secure: UYzfd4QYLtAX39r8LzV1dYp7cKMhYRRjI/xswMEkR+RgdMWxVPPH3kcsNLwkdNGSPn1b8Aidz8YLss9JolrepWjwI283dK8EUthZAOw03+PmL5X/3nOJ7aGv0sxwYqF5ypltBrerTf6jtPUTcQdtao+0O8bgnzShc6nWWE4MLXonjOm1pZLRUo81un+0bzm8C2ABIeHC6xuZCRycXP5u1mW1nDLK3900uY1rxIDTSZKEzA0IzLQhE9uROvI1r48fW8cKJQQjMMO5PPorq+0eDl2YTE8rQr9ldvuRE7A/ubsOQR0N5F8iAv1JTZXuXGt62fw6eKDQ1h94suEk7X+baV0EwlfhsHXcI1MxRFwxNSr9k1WaVFfA4TrM8XYBAcW3JGRA51ZK3q4EcjpuxpupaA7kZDtH53W7ePzH2TIp6yknln1q+yfcsP7cGv38sSKpKwOyMgAPRElkZzcoo31kw/PLzKPXYJEovRqx/0lWzczbFSscsroNaGCavC02++bUnyUXW2W+PG4gDSBFVZjtrvTPKnZ6DpHXV97x6xC/CzyhFj/Nf+ao/J9IIfocnc4vXJojwS550KIvM7xCDJwa/+29dajj2l6dQqrcOe3UT3O5UGU9I0KkGEDMfkLOD71eRy58qiYz3y953e52DvvzWQJbvfuk8ubMO+Fmn4GyRz8=
#notifications:
# slack:
# secure: UYzfd4QYLtAX39r8LzV1dYp7cKMhYRRjI/xswMEkR+RgdMWxVPPH3kcsNLwkdNGSPn1b8Aidz8YLss9JolrepWjwI283dK8EUthZAOw03+PmL5X/3nOJ7aGv0sxwYqF5ypltBrerTf6jtPUTcQdtao+0O8bgnzShc6nWWE4MLXonjOm1pZLRUo81un+0bzm8C2ABIeHC6xuZCRycXP5u1mW1nDLK3900uY1rxIDTSZKEzA0IzLQhE9uROvI1r48fW8cKJQQjMMO5PPorq+0eDl2YTE8rQr9ldvuRE7A/ubsOQR0N5F8iAv1JTZXuXGt62fw6eKDQ1h94suEk7X+baV0EwlfhsHXcI1MxRFwxNSr9k1WaVFfA4TrM8XYBAcW3JGRA51ZK3q4EcjpuxpupaA7kZDtH53W7ePzH2TIp6yknln1q+yfcsP7cGv38sSKpKwOyMgAPRElkZzcoo31kw/PLzKPXYJEovRqx/0lWzczbFSscsroNaGCavC02++bUnyUXW2W+PG4gDSBFVZjtrvTPKnZ6DpHXV97x6xC/CzyhFj/Nf+ao/J9IIfocnc4vXJojwS550KIvM7xCDJwa/+29dajj2l6dQqrcOe3UT3O5UGU9I0KkGEDMfkLOD71eRy58qiYz3y953e52DvvzWQJbvfuk8ubMO+Fmn4GyRz8=

View File

@ -46,6 +46,12 @@ Custom library steps can be added using a custom library according to the
groovy coding to the `Jenkinsfile`. Your custom library can coexist next to the
provided pipeline library.
## API
All steps are intended to be used by Pipelines. All the classes / groovy-scripts
contained in the `src` folder are not part of the API and are subjected to change
without prior notice.
# Requirements
* Java Runtime Environment 8

BIN
cfg/id_rsa.enc Normal file

Binary file not shown.

View File

@ -1,155 +0,0 @@
# ConfigurationLoader
## Description
Loads configuration values from the global configuration.
The global configuration is stored in the commonPipelineEnvironment and should be loaded before by calling setupCommonPipelineEnvironment.
## Static Method Details
### stepConfiguration
#### Description
Returns the configuration for a specific step as map.
#### Parameters
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`][commonPipelineEnvironment] for retrieving, for example, configuration parameters.
* `stepName` - The name of the step
#### Side effects
none
#### Example
In your `config.yml` you define the following:
```
#Steps Specific Configuration
steps:
mavenExecute:
dockerImage: 'maven:3.5-jdk-7'
```
To get the map containing the key `dockerImage` and the value `maven:3.5-jdk-7` you have to execute the following:
```groovy
Map configuration = ConfigurationLoader.stepConfiguration(script, 'mavenExecute')
```
### defaultStepConfiguration
#### Description
Returns the default configuration for a specific step as map.
#### Parameters
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`][commonPipelineEnvironment] for retrieving, for example, configuration parameters.
* `stepName` - The name of the step
#### Side effects
none
#### Example
To get the map of the default values defined in the file `resources/default_pipeline_environment.yml` you have to execute the following:
```groovy
Map configuration = ConfigurationLoader.defaultStepConfiguration(script, 'mavenExecute')
```
### generalConfiguration
#### Description
Returns the configuration in the section general of the configuration file.
#### Parameters
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`][commonPipelineEnvironment] for retrieving, for example, configuration parameters.
#### Side effects
none
#### Example
In your `config.yml` you define the following:
```
#Project Setup
general:
productiveBranch: 'master'
```
To get the map containing the key `productiveBranch` and the value `master` you have to execute the following:
```groovy
Map configuration = ConfigurationLoader.generalConfiguration(script)
```
### defaultGeneralConfiguration
#### Description
Returns the default configuration in the section general of the default configuration file.
#### Parameters
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`][commonPipelineEnvironment] for retrieving, for example, configuration parameters.
#### Side effects
none
#### Example
To get the map of the default values defined in the file `resources/default_pipeline_environment.yml` you have to execute the following:
```groovy
Map configuration = ConfigurationLoader.defaultGeneralConfiguration(script)
```
### stageConfiguration
#### Description
Returns the configuration for a specific stage as map.
This is useful if you decide to have a central pipeline and want to give all your projects the possibility to configure the stages in the central pipeline.
Thus, the central pipeline can define how to deploy and read the configuration.
In the their configuration files, all the projects can configure the location where to deploy.
#### Parameters
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`][commonPipelineEnvironment] for retrieving, for example, configuration parameters.
* `script` - Name of the stage as defined in the configuration file.
#### Side effects
none
#### Example
In your `config.yml` you define the following:
```
#Project Setup
#Stage Specific Configurations
stages:
productionDeployment:
targets:
- apiEndpoint: 'https://api.cf.sap.hana.ondemand.com'
org: 'myOrg'
manifest: 'manifest.yml'
appName: 'my-app'
```
To get the map containing the key `targets` and the list of the deployment locations.
```groovy
Map configuration = ConfigurationLoader.stageConfiguration(script, 'productionDeployment')
```
[commonPipelineEnvironment]: /steps/commonPipelineEnvironment.md

View File

@ -1,123 +0,0 @@
# ConfigurationMerger
## Description
A helper script that can merge the configurations from multiple sources.
## Static Method Details
### merge
#### Description
A step is usually configured by default values, configuration values from the configuration file and the parameters.
The method can merge these sources.
Default values are overwritten by configuration file values.
These are overwritten by parameters.
#### Parameters
| parameter | mandatory | Class |
| -------------------|-----------|-----------------------------------|
| `parameters` | yes | Map |
| `parameterKeys` | yes | List |
| `configurationMap` | yes | Map |
| `configurationKeys`| yes | List |
| `defaults` | yes | Map |
* `parameters` Parameters map given to the step
* `parameterKeys` List of parameter names (keys) that should be considered while merging.
* `configurationMap` Configuration map loaded from the configuration file.
* `configurationKeys` List of configuration keys that should be considered while merging.
* `defaults` Map of default values, e.g. loaded from the default value configuration file.
#### Side effects
none
#### Example
```groovy
prepareDefaultValues script: script
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, 'mavenExecute')
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, 'mavenExecute')
List parameterKeys = [
'dockerImage',
'globalSettingsFile',
'projectSettingsFile',
'pomPath',
'flags',
'goals',
'm2Path',
'defines'
]
List stepConfigurationKeys = [
'dockerImage',
'globalSettingsFile',
'projectSettingsFile',
'pomPath',
'm2Path'
]
Map configuration = ConfigurationMerger.merge(parameters, parameterKeys, stepConfiguration, stepConfigurationKeys, stepDefaults)
```
### mergeWithPipelineData
#### Description
A step is usually configured by default values, configuration values from the configuration file and the parameters.
In certain cases also information previously generated in the pipeline should be mixed in, like for example an artifactVersion created earlier.
The method can merge these sources.
Default values are overwritten by configuration file values.
Those are overwritten by information previously generated in the pipeline (e.g. stored in [commonPipelineEnvironment](../steps/commonPipelineEnvironment.md)).
These are overwritten by parameters passed directly to the step.
#### Parameters
| parameter | mandatory | Class |
| -------------------|-----------|-----------------------------------|
| `parameters` | yes | Map |
| `parameterKeys` | yes | List |
| `pipelineDataMap` | yes | Map |
| `configurationMap` | yes | Map |
| `configurationKeys`| yes | List |
| `defaults` | yes | Map |
* `parameters` Parameters map given to the step
* `parameterKeys` List of parameter names (keys) that should be considered while merging.
* `configurationMap` Configuration map loaded from the configuration file.
* `pipelineDataMap` Values available to the step during pipeline run.
* `configurationKeys` List of configuration keys that should be considered while merging.
* `defaults` Map of default values, e.g. loaded from the default value configuration file.
#### Side effects
none
#### Example
```groovy
def stepName = 'influxWriteData'
prepareDefaultValues script: script
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)
final Map generalConfiguration = ConfigurationLoader.generalConfiguration(script)
List parameterKeys = [
'artifactVersion',
'influxServer',
'influxPrefix'
]
Map pipelineDataMap = [
artifactVersion: commonPipelineEnvironment.getArtifactVersion()
]
List stepConfigurationKeys = [
'influxServer',
'influxPrefix'
]
Map configuration = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, stepConfiguration, stepConfigurationKeys, stepDefaults)
```

View File

@ -1,64 +0,0 @@
# FileUtils
## Description
Provides file system related utility functions.
## Constructor
Since there are only static utility methods there is no need for instantiating objects.
## Method Details
### validateDirectory(dir)
#### Description
Checks whether a file exists and is a directory.
#### Parameters
* `dir` - The directory to be checked. In case it is relative path it is checked against the
current working directory. In case of doubt use the absolute path (prefix the directory with `pwd`).
#### Return value
none
#### Side effects
none
#### Exceptions
* `IllegalArgumentException`:
* If the parameter `dir` is null or empty.
* `AbortException`:
* If the directory does not exist or is not a directory.
#### Example
```groovy
FileUtils.validateDirectory('/path/to/dir')
```
### validateDirectoryIsNotEmpty(dir)
#### Description
Check whether a directory is not empty. Before the directory is checked, `validateDirectory(dir)` is executed.
#### Parameters
* `dir` - The directory to be checked. In case it is relative path it is checked against the
current working directory. In case of doubt use the absolute path (prefix the directory with `pwd`).
#### Return value
none
#### Side effects
none
#### Exceptions
* `IllegalArgumentException`:
* If the parameter `dir` is null or empty.
* `AbortException`:
* If the directory does not exist or is not a directory or the directory is empty.
#### Example
```groovy
FileUtils.validateDirectoryIsNotEmpty('/path/to/dir')
```

View File

@ -1,30 +0,0 @@
# JsonUtils
## Description
Provides json related utility functions.
## Constructors
### JsonUtils()
Default no-argument constructor. Instances of the Utils class does not hold any instance specific state.
#### Example
```groovy
new JsonUtils()
```
## Method Details
### getPrettyJsonString(object)
#### Description
Creates a pretty-printed json string.
#### Parameters
* `object` - A object (e.g. Map or List).
#### Return value
A pretty printed `String`.
#### Side effects
none

View File

@ -1,67 +0,0 @@
# Utils
## Description
Provides utility functions.
## Constructors
### Utils()
Default no-argument constructor. Instances of the Utils class does not hold any instance specific state.
#### Example
```groovy
new Utils()
```
## Method Details
### getMandatoryParameter(map, paramName, defaultValue)
#### Description
Retrieves the parameter value for parameter `paramName` from parameter map `map`. In case there is no parameter with the given key contained in parameter map `map` `defaultValue` is returned. In case there no such parameter contained in `map` and `defaultValue` is `null` an exception is thrown.
#### Parameters
* `map` - A map containing configuration parameters.
* `paramName` - The key of the parameter which should be looked up.
* optional: `defaultValue` - The value which is returned in case there is no parameter with key `paramName` contained in `map`. If it is not provided the default is `null`.
#### Return value
The value to the parameter to be retrieved, or the default value if the former is `null`, either since there is no such key or the key is associated with value `null`. In case the parameter is not defined or the value for that parameter is `null`and there is no default value an exception is thrown.
#### Side effects
none
#### Exceptions
* `Exception`:
* If the value to be retrieved and the default value are both `null`.
#### Example
```groovy
def utils = new Utils()
def parameters = [DEPLOY_ACCOUNT: 'deploy-account']
assert utils.getMandatoryParameter(parameters, 'DEPLOY_ACCOUNT', null) == 'deploy-account'
assert utils.getMandatoryParameter(parameters, 'DEPLOY_USER', 'john_doe') == 'john_doe'
```
### retrieveGitCoordinates(script)
#### Description
Retrieves the git-remote-url and git-branch. The parameters 'GIT_URL' and 'GIT_BRANCH' are retrieved from Jenkins job configuration. If these are not set, the git-url and git-branch are retrieved from the same repository where the Jenkinsfile resides.
#### Parameters
* `script` - The script calling the method. Basically the `Jenkinsfile`. It is assumed that the script provides access to the parameters defined when launching the build, especially `GIT_URL` and `GIT_BRANCH`.
#### Return value
A map containing git-url and git-branch: `[url: gitUrl, branch: gitBranch]`
## Exceptions
* `AbortException`:
* If only one of `GIT_URL`, `GIT_BRANCH` is set in the Jenkins job configuration.
#### Example
```groovy
def gitCoordinates = new Utils().retrieveGitCoordinates(this)
def gitUrl = gitCoordinates.url
def gitBranch = gitCoordinates.branch
```

View File

@ -1,147 +0,0 @@
# Version
## Description
Handles version numbers.
## Constructors
### Version(major, minor, patch)
#### Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
| major | yes | | |
| minor | yes | | |
| patch | no | `-1` | |
* `major` - The major version number.
* `minor` - The minor version number.
* `patch` - The patch version number.
#### Exceptions
* `IllegalArgumentException`:
* If the `major` or `minor` version number is less than `0`.
#### Example
```groovy
def toolVersion = new Version(1, 2, 3)
```
### Version(text)
#### Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
| text | yes | | |
* `text` - As an alternative to calling the constructor with `major`, `minor`, and `patch` version numbers, you can pass this as a String of format 'major.minor.patch'.
#### Exceptions
* `IllegalArgumentException`:
* If the `text` parameter is `null` or empty.
* `AbortException`:
* If the version `text` has an unexpected format.
#### Example
```groovy
def toolVersion = new Version('1.2.3')
```
## Method Details
### equals(version)
#### Description
Indicates whether some other version instance is equal to this one. The two versions are considered equal when they have the same `major`, `minor` and `patch` version number.
#### Parameters
* `version` - The Version instance to compare to this Version instance.
#### Return value
`true` if `major`, `minor` and `patch` version numbers are equal to each other. Otherwise `false`.
#### Side effects
none
#### Exceptions
* `AbortException`:
* If the parameter `version` is `null`.
#### Example
```groovy
assert new Version('1.2.3').equals(new Version('1.2.3'))
```
### isCompatibleVersion(version)
#### Description
Checks whether a version is compatible. Two versions are compatible if the major version number is the same, while the minor and patch version number are the same or higher.
#### Parameters
* `version` - The Version instance to compare to this Version instance.
#### Return value
`true` if this Version instance is compatible to the other Version instance. Otherwise `false`.
#### Side effects
none
#### Exceptions
* `AbortException`:
* If the parameter `version` is `null`.
#### Example
```groovy
assert new Version('1.2.3').isCompatibleVersion(new Version('1.3.1'))
```
### isHigher(version)
#### Description
Checks whether this Version instance is higher than the other Version instance.
#### Parameters
* `version` - The Version instance to compare to this Version instance.
#### Return value
`true` if this Version instance is higher than the other Version instance. Otherwise `false`.
#### Side effects
none
#### Exceptions
* `AbortException`:
* If the parameter `version` is `null`.
#### Example
```groovy
assert new Version('1.2.3').isHigher(new Version('1.1.6'))
```
### toString()
#### Description
Print the version number in format '<major>.<minor>.<patch>'. If no patch version number exists the format is '<major>.<minor>'.
#### Parameters
none
#### Return value
A String consisting of `major`, `minor` and if available `patch`, separated by dots.
#### Side effects
none
#### Exceptions
none
#### Example
```groovy
assert "${new Version('1.2.3')}" == "1.2.3"
```

View File

@ -9,7 +9,10 @@ The version generated using this step will contain:
* Timestamp
* CommitId (by default the long version of the hash)
After conducting automatic versioning the new version is pushed as a new tag into the source code repository (e.g. GitHub)
Optionally, but enabled by default, the new version is pushed as a new tag into the source code repository (e.g. GitHub).
If this option is chosen, git credentials and the repository URL needs to be provided.
Since you might not want to configure the git credentials in Jenkins, committing and pushing can be disabled using the `commitVersion` parameter as described below.
If you require strict reproducibility of your builds, this should be used.
## Prerequsites
none
@ -19,21 +22,25 @@ none
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
| script | no | empty `commonPipelineEnvironment` | |
| artifactType | no | | 'appContainer' |
| buildTool | no | maven | maven, docker |
| commitVersion | no | `true` | `true`, `false` |
| dockerVersionSource | no | `''` | FROM, (ENV name),appVersion |
| filePath | no | buildTool=`maven`: pom.xml <br />docker: Dockerfile | |
| gitCommitId | no | `GitUtils.getGitCommitId()` | |
| gitCredentialsId | yes | as defined in custom configuration | |
| gitCredentialsId | If `commitVersion` is `true` | as defined in custom configuration | |
| gitUserEMail | no | | |
| gitUserName | no | | |
| gitSshUrl | yes | | |
| gitSshUrl | If `commitVersion` is `true` | | |
| tagPrefix | no | 'build_' | |
| timestamp | no | current time in format according to `timestampTemplate` | |
| timestampTemplate | no | `%Y%m%d%H%M%S` | |
| versioningTemplate | no | depending on `buildTool`<br />maven: `${version}-${timestamp}${commitId?"_"+commitId:""}` | |
* `script` defines the global script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving e.g. configuration parameters.
* `artifactType` defines the type of the artifact.
* `buildTool` defines the tool which is used for building the artifact.
* `commitVersion` controls if the changed version is committed and pushed to the git repository. If this is enabled (which is the default), you need to provide `gitCredentialsId` and `gitSshUrl`.
* `dockerVersionSource` specifies the source to be used for the main version which is used for generating the automatic version.
* This can either be the version of the base image - as retrieved from the `FROM` statement within the Dockerfile, e.g. `FROM jenkins:2.46.2`
@ -49,10 +56,11 @@ none
* `timestamp` defines the timestamp to be used in the automatic version string. You could overwrite the default behavior by explicitly setting this string.
## Step configuration
Following parameters can also be specified as step parameters using the global configuration file:
The following parameters can also be specified as step parameters using the global configuration file:
* `artifactType`
* `buildTool`
* `commitVersion`
* `dockerVersionSource`
* `filePath`
* `gitCredentialsId`
@ -64,9 +72,7 @@ Following parameters can also be specified as step parameters using the global c
* `timestampTemplate`
* `versioningTemplate`
## Explanation of pipeline step
Pipeline step:
## Example
```groovy
artifactSetVersion script: this, buildTool: 'maven'

View File

@ -102,6 +102,19 @@ Each of the parameters `aggregation`, `tasks`, `pmd`, `cpd`, `findbugs`, `checks
| archive | no | `true` | `true`, `false` |
| thresholds | no | none | see [thresholds](#thresholds) |
## Step configuration
Following parameters can also be specified as step parameters using the global configuration file:
* `aggregation`
* `tasks`
* `pmd`
* `cpd`
* `findbugs`
* `checkstyle`
* `eslint`
* `pylint`
* `archive`
### Thresholds
It is possible to define thresholds to fail the build on a certain count of findings. To achive this, just define your thresholds a followed for the specific check tool:

View File

@ -17,9 +17,12 @@ Proxy environment variables defined on the Jenkins machine are also available in
* `dockerImage` Name of the docker image that should be used. If empty, Docker is not used.
* `dockerEnvVars` Environment variables to set in the container, e.g. [http_proxy:'proxy:8080']
* `dockerOptions` Docker options to be set when starting the container.
* `dockerOptions` Docker options to be set when starting the container. It can be a list or a string.
* `dockerVolumeBind` Volumes that should be mounted into the container.
## Step configuration
None
## Exceptions
None

View File

@ -14,16 +14,7 @@ none
## Pipeline configuration
none
## Explanation of pipeline step
Usage of pipeline step:
```groovy
durationMeasure (script: this, measurementName: 'build_duration') {
//execute your build
}
```
Available parameters:
## Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
@ -35,3 +26,13 @@ Details:
* `script` defines the global script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for storing the measured duration.
* `measurementName` defines the name of the measurement which is written to the Influx database.
## Step configuration
none
## Example
```groovy
durationMeasure (script: this, measurementName: 'build_duration') {
//execute your build
}
```

View File

@ -38,6 +38,9 @@ none
----------------------------------------------------------
```
## Step configuration
none
## Return value
none

View File

@ -80,16 +80,7 @@ You need to define the influxDB server in your pipeline as it is defined in the
influxDBServer=jenkins
```
## Explanation of pipeline step
Example usage of pipeline step:
```groovy
influxWriteData script: this
```
Available parameters:
## Parameters
| parameter | mandatory | default | possible values |
| ----------|-----------|---------|-----------------|
@ -98,6 +89,17 @@ Available parameters:
| influxServer | no | `jenkins` | |
| influxPrefix | no | `null` | |
## Step configuration
The following parameters can also be specified as step parameters using the global configuration file:
* `influxServer`
* `influxPrefix`
## Example
```groovy
influxWriteData script: this
```
## Work with InfluxDB and Grafana

View File

@ -26,8 +26,9 @@ Executes a maven command inside a Docker container.
* `m2Path` Path to the location of the local repository that should be used.
* `defines` Additional properties.
## Global Configuration
The following parameters can also be specified using the global configuration file:
## Step configuration
The following parameters can also be specified as step parameters using the global configuration file:
* `dockerImage`
* `globalSettingsFile`
* `projectSettingsFile`

View File

@ -9,15 +9,24 @@ Executes the SAP MTA Archive Builder to create an mtar archive of the applicatio
* **NodeJS installed** - the MTA Builder uses `npm` to download node module dependencies such as `grunt`.
## Parameters
| parameter | mandatory | default | possible values |
| -----------------|-----------|-----------------------------------|--------------------|
| `script` | yes | | |
| `buildTarget` | yes | | 'CF', 'NEO', 'XSA' |
| `mtaJarLocation` | no | | |
| parameter | mandatory | default | possible values |
| -----------------|-----------|--------------------------------------------------------|--------------------|
| `script` | yes | | |
| `buildTarget` | yes | `'NEO'` | 'CF', 'NEO', 'XSA' |
| `mtaJarLocation` | no | | |
| `applicationName`| no | | |
* `script` - The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the `this` parameter, as in `script: this`. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving, for example, configuration parameters.
* `buildTarget` - The target platform to which the mtar can be deployed.
* `mtaJarLocation` - The path of the `mta.jar` file. If no parameter is provided, the path is retrieved from the Jenkins environment variables using `env.MTA_JAR_LOCATION`. If the Jenkins environment variable is not set it is assumed that `mta.jar` is located in the current working directory.
* `mtaJarLocation` - The path of the `mta.jar` file. If no parameter is provided, neither at the level of the method call nor via step configuration, the path is retrieved from the Jenkins environment variables using `env.MTA_JAR_LOCATION`. If the Jenkins environment variable is not set it is assumed that `mta.jar` is located in the current working directory.
* `applicationName` - The name of the application which is being built. If the parameter has been provided and no `mta.yaml` exists, the `mta.yaml` will be automatically generated using this parameter and the information (`name` and `version`) from `package.json` before the actual build starts.
## Step configuration
The following parameters can also be specified as step parameters using the global configuration file:
* `buildTarget`
* `mtaJarLocation`
* `applicationName`
## Return value
The file name of the resulting archive is returned with this step. The file name is extracted from the key `ID` defined in `mta.yaml`.
@ -37,3 +46,4 @@ dir('/path/to/FioriApp'){
mtarFileName = mtaBuild script:this, buildTarget: 'NEO'
}
```

View File

@ -17,56 +17,76 @@ needs to be extracted into the folder provided by `neoHome`. In case this parame
* **Java 8 or higher** - needed by the *Neo-Java-Web-SDK*
## Parameters when using MTA deployment method (default - MTA)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------------------------------------------|-----------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `deployHost` | no | `'account'` from step configuration `'neoDeploy'`, or propertey `'DEPLOY_HOST'` from `commonPipelineEnvironment` (deprecated) | |
| `deployAccount` | no | `'host'` from step configuration `'neoDeploy'`, or property `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` (deprecated) | |
| `neoCredentialsId` | no | `'neoCredentialsId'` from step configuration `'neoDeploy'` or hard coded value `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
| parameter | mandatory | default | possible values |
| -------------------|-----------|-------------------------------|-------------------------------------------------|
| `account` | no | | |
| `archivePath` | yes | | |
| `deployAccount` deprecated, use `account` | no | | |
| `deployHost` deprecated, use `host` | no | | |
| `deployMode` | yes | `'mta'` | `'mta'`, `'warParams'`, `'warPropertiesFile'` |
| `host` | no | | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | | |
| `script` | yes | | |
## Parameters when using WAR file deployment method with .properties file (WAR_PROPERTIESFILE)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
| `propertiesFile` | yes | | |
| parameter | mandatory | default | possible values |
| -------------------|-----------|-------------------------------|-------------------------------------------------|
| `archivePath` | yes | | |
| `deployMode` | yes | `'mta'` | `'mta'`, `'warParams'`, `'warPropertiesFile'` |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | | |
| `propertiesFile` | yes | | |
| `script` | yes | | |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
## Parameters when using WAR file deployment method witout .properties file - with parameters (WAR_PARAMS)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `deployHost` | no | `'DEPLOY_HOST'` from `commonPipelineEnvironment` | |
| `deployAccount` | no | `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
| `applicationName` | yes | | |
| `runtime` | yes | | |
| `runtime-version` | yes | | |
| `size` | no | `'lite'` | `'lite'`, `'pro'`, `'prem'`, `'prem-plus'` |
| parameter | mandatory | default | possible values |
| -------------------|-----------|-------------------------------|-------------------------------------------------|
| `account` | no | | |
| `applicationName` | yes | | |
| `archivePath` | yes | | |
| `deployAccount` deprecated, use `account` | no | |
| `deployHost` deprecated, use `host` | no | |
| `deployMode` | yes | `'mta'` | `'mta'`, `'warParams'`, `'warPropertiesFile'` |
| `host` | no | | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | | |
| `runtime` | yes | | |
| `runtime-version` | yes | | |
| `script` | yes | | |
| `vmSize` | no | `'lite'` | `'lite'`, `'pro'`, `'prem'`, `'prem-plus'` |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
* `deployMode` - The deployment mode which should be used. Available options are `'MTA'` (default), `'WAR_PARAMS'` (deploying WAR file and passing all the deployment parameters via the function call) and `'WAR_PROPERTIESFILE'` (deploying WAR file and putting all the deployment parameters in a .properties file)
* `script` - The common script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving e.g. configuration parameters.
* `account` - The SAP Cloud Platform account to deploy to.
* `applicationName` - Name of the application you want to manage, configure, or deploy
* `archivePath`- The path to the archive for deployment to SAP CP.
* `deployHost` - The SAP Cloud Platform host to deploy to.
* `deployAccount` - The SAP Cloud Platform account to deploy to.
* `credentialsId` - The Jenkins credentials containing user and password used for SAP CP deployment.
* `deployAccount` - deprecated, use `account`. The SAP Cloud Platform account to deploy to.
* `deployHost` - deprecated, use `host`. The SAP Cloud Platform host to deploy to.
* `deployMode` - The deployment mode which should be used. Available options are `'mta'` (default), `'warParams'` (deploying WAR file and passing all the deployment parameters via the function call) and `'warPropertiesFile'` (deploying WAR file and putting all the deployment parameters in a .properties file)
* `host` - The SAP Cloud Platform host to deploy to.
* `neoCredentialsId` - The Jenkins credentials containing user and password used for SAP CP deployment.
* `neoHome` - The path to the `neo-java-web-sdk` tool used for SAP CP deployment. If no parameter is provided, the path is retrieved from the Jenkins environment variables using `env.NEO_HOME`. If this Jenkins environment variable is not set it is assumed that the tool is available in the `PATH`.
* `propertiesFile` - The path to the .properties file in which all necessary deployment properties for the application are defined.
* `warAction` - Action mode when using WAR file mode. Available options are `deploy` (default) and `rolling-update` which performs update of an application without downtime in one go.
* `applicationName` - Name of the application you want to manage, configure, or deploy
* `runtime` - Name of SAP Cloud Platform application runtime
* `runtime-version` - Version of SAP Cloud Platform application runtime
* `size` - Compute unit (VM) size. Acceptable values: lite, pro, prem, prem-plus.
* `script` - The common script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving e.g. configuration parameters.
* `vmSize` - Compute unit (VM) size. Acceptable values: lite, pro, prem, prem-plus.
* `warAction` - Action mode when using WAR file mode. Available options are `deploy` (default) and `rolling-update` which performs update of an application without downtime in one go.
The step is prepared for being executed in docker. The corresponding parameters can be applied. See step `dockerExecute` for details.
## Step configuration
The following parameters can also be specified as step parameters using the global configuration file:
* `account`
* `dockerEnvVars`
* `dockerImage`
* `dockerOptions`
* `host`
* `neoCredentialsId`
* `neoHome`
## Return value
none

View File

@ -25,6 +25,10 @@ none
* `path` The path to the Jenkinsfile, inside the repository, to be loaded.
* `credentialsId` The Jenkins credentials containing user and password needed to access a private git repository.
## Step configuration
none
## Return value
none

View File

@ -9,6 +9,10 @@ Afterwards the values can be loaded by the method: `ConfigurationLoader.defaultS
None
## Step configuration
None
## Exceptions
None

View File

@ -20,6 +20,9 @@ Initializes the [`commonPipelineEnvironment`](commonPipelineEnvironment.md), whi
* `script` - The reference to the pipeline script (Jenkinsfile). Normally `this` needs to be provided.
* `configFile` - Property file defining project specific settings.
## Step configuration
none
## Return value
none

View File

@ -16,6 +16,9 @@ none
* `tool` The tool that is checked for existence and compatible version.
* `home` The location in the file system where Jenkins can access the tool.
## Step configuration
none
## Return value
none
@ -33,6 +36,3 @@ none
toolValidate tool: 'neo', home:'/path/to/neo-java-web-sdk'
```

View File

@ -15,13 +15,6 @@ pages:
- prepareDefaultValues: steps/prepareDefaultValues.md
- setupCommonPipelineEnvironment: steps/setupCommonPipelineEnvironment.md
- toolValidate: steps/toolValidate.md
- 'Library scripts':
- FileUtils: scripts/fileUtils.md
- JsonUtils: scripts/jsonUtils.md
- Utils: scripts/utils.md
- Version: scripts/version.md
- ConfigurationLoader: scripts/configurationLoader.md
- ConfigurationMerger: scripts/configurationMerger.md
- 'Required Plugins': jenkins/requiredPlugins.md
theme:

15
gh-pages-deploy.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
echo "Found change on master: Deployment of documentation"
PRIVATE_KEY="cfg/id_rsa"
chmod 600 "${PRIVATE_KEY}"
eval `ssh-agent -s`
ssh-add "${PRIVATE_KEY}"
git config user.name "Travis CI Publisher"
git remote add docu "git@github.com:$TRAVIS_REPO_SLUG.git";
git fetch docu gh-pages:gh-pages
echo "Pushing to gh-pages of repository $TRAVIS_REPO_SLUG"
cd $TRAVIS_BUILD_DIR/documentation
mkdocs gh-deploy -v --clean --remote-name docu

View File

@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.sap.cp.jenkins</groupId>
<artifactId>jenkins-library</artifactId>
<version>0.2</version>
<version>0.3</version>
<name>SAP CP Piper Library</name>
<description>Shared library containing steps and utilities to set up continuous deployment processes for SAP technologies.</description>

View File

@ -7,6 +7,7 @@ steps:
artifactSetVersion:
timestampTemplate: '%Y%m%d%H%M%S'
tagPrefix: 'build_'
commitVersion: true
maven:
filePath: 'pom.xml'
versioningTemplate: '${version}-${timestamp}${commitId?"_"+commitId:""}'

View File

@ -0,0 +1,16 @@
_schema-version: "2.0.0"
ID: "<Id of your MTA>"
version: <version number of your application>
parameters:
hcp-deployer-version: "1.0.0"
modules:
- name: "<Name of your Fiori application>"
type: html5
path: .
parameters:
version: <version number of your application>-${timestamp}
build-parameters:
builder: grunt
build-result: dist

View File

@ -1,8 +1,42 @@
package com.sap.piper
class ConfigurationHelper implements Serializable {
static def loadStepDefaults(Script step){
return new ConfigurationHelper(step)
.initDefaults(step)
.loadDefaults()
}
private final Map config
private Map config
private String name
ConfigurationHelper(Script step){
name = step.STEP_NAME
if(!name) throw new IllegalArgumentException('Step has no public name property!')
}
private final ConfigurationHelper initDefaults(Script step){
step.prepareDefaultValues()
return this
}
private final ConfigurationHelper loadDefaults(){
config = ConfigurationLoader.defaultStepConfiguration(null, name)
return this
}
ConfigurationHelper mixinStepConfig(commonPipelineEnvironment, Set filter = null){
if(!name) throw new IllegalArgumentException('Step has no public name property!')
Map stepConfiguration = ConfigurationLoader.stepConfiguration([commonPipelineEnvironment: commonPipelineEnvironment], name)
return mixin(stepConfiguration, filter)
}
ConfigurationHelper mixin(Map parameters, Set filter = null){
config = ConfigurationMerger.merge(parameters, filter, config)
return this
}
Map use(){ return config }
ConfigurationHelper(Map config = [:]){
this.config = config

View File

@ -6,7 +6,7 @@ import com.sap.piper.MapUtils
class ConfigurationMerger {
@NonCPS
def static merge(Map configs, List configKeys, Map defaults) {
def static merge(Map configs, Set configKeys, Map defaults) {
Map filteredConfig = configKeys?configs.subMap(configKeys):configs
Map merged = [:]
@ -23,8 +23,8 @@ class ConfigurationMerger {
@NonCPS
def static merge(
Map parameters, List parameterKeys,
Map configuration, List configurationKeys,
Map parameters, Set parameterKeys,
Map configuration, Set configurationKeys,
Map defaults=[:]
){
Map merged
@ -34,9 +34,31 @@ class ConfigurationMerger {
}
@NonCPS
def static mergeWithPipelineData(Map parameters, List parameterKeys,
def static merge(
def script, def stepName,
Map parameters, Set parameterKeys,
Set stepConfigurationKeys
) {
merge(script, stepName, parameters, parameterKeys, [:], stepConfigurationKeys)
}
@NonCPS
def static merge(
def script, def stepName,
Map parameters, Set parameterKeys,
Map pipelineData,
Set stepConfigurationKeys
) {
Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)
Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)
mergeWithPipelineData(parameters, parameterKeys, pipelineData, stepConfiguration, stepConfigurationKeys, stepDefaults)
}
@NonCPS
def static mergeWithPipelineData(Map parameters, Set parameterKeys,
Map pipelineDataMap,
Map configurationMap, List configurationKeys,
Map configurationMap, Set configurationKeys,
Map stepDefaults=[:]
){
Map merged
@ -46,19 +68,4 @@ class ConfigurationMerger {
return merged
}
@NonCPS
def static merge(
Map parameters, List parameterKeys,
Map generalConfigurationMap, List generalConfigurationKeys, Map generalConfigurationDefaults,
Map stepConfigurationMap, List stepConfigurationKeys, Map stepConfigurationDefaults=[:]
){
Map merged
Map mergedStepConfiguration = merge(stepConfigurationMap, stepConfigurationKeys, stepConfigurationDefaults)
Map mergedGeneralConfiguration = merge(generalConfigurationMap, generalConfigurationKeys, generalConfigurationDefaults)
merged = merge(mergedGeneralConfiguration, null, mergedStepConfiguration)
merged = merge(parameters, parameterKeys, merged)
return merged
}
}

View File

@ -1,6 +1,12 @@
package com.sap.piper
import com.cloudbees.groovy.cps.NonCPS
def getGitCommitIdOrNull() {
if (fileExists('.git')) {
return sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
} else {
return null
}
}
def getGitCommitId() {
return sh(returnStdout: true, script: 'git rev-parse HEAD').trim()

View File

@ -0,0 +1,40 @@
package com.sap.piper
import java.util.Map
import hudson.AbortException
class MtaUtils {
final protected script
protected MtaUtils(script) {
this.script = script
}
def generateMtaDescriptorFromPackageJson (String srcPackageJson, String targetMtaDescriptor, String applicationName) throws Exception{
if (!srcPackageJson) throw new IllegalArgumentException("The parameter 'srcPackageJson' can not be null or empty.")
if (!targetMtaDescriptor) throw new IllegalArgumentException("The parameter 'targetMtaDescriptor' can not be null or empty.")
if (!applicationName) throw new IllegalArgumentException("The parameter 'applicationName' can not be null or empty.")
if (!script.fileExists(srcPackageJson)) throw new AbortException("'${srcPackageJson}' does not exist.")
def dataFromJson = script.readJSON file: srcPackageJson
def mtaData = script.readYaml text: script.libraryResource('template_mta.yml')
if(!dataFromJson.name) throw new AbortException("'name' not set in the given package.json.")
mtaData['ID'] = dataFromJson.name
if(!dataFromJson.version) throw new AbortException("'version' not set in the given package.json.")
mtaData['version'] = dataFromJson.version
mtaData['modules'][0]['parameters']['version'] = "${dataFromJson.version}-\${timestamp}"
mtaData['modules'][0]['name'] = applicationName
script.writeYaml file: targetMtaDescriptor, data: mtaData
if (!script.fileExists(targetMtaDescriptor)) throw new AbortException("'${targetMtaDescriptor}' has not been generated.")
}
}

View File

@ -13,6 +13,6 @@ class MavenArtifactVersioning extends ArtifactVersioning {
@Override
def setVersion(version) {
script.sh "mvn versions:set -DnewVersion=${version} --file ${configuration.filePath}"
script.mavenExecute script: script, goals: 'versions:set', defines: "-DnewVersion=${version}", pomPath: configuration.filePath
}
}

View File

@ -0,0 +1,34 @@
#!groovy
import com.lesfurets.jenkins.unit.BasePipelineTest
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.Rules
import util.JenkinsStepRule
class StepTestTemplateTest extends BasePipelineTest {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(jsr)
@Before
void init() throws Exception {
}
@Test
void testStepTestTemplate() throws Exception {
jsr.step.call()
// asserts
assertEquals(true != false)
assertTrue(true)
assertJobStatusSuccess()
}
}

View File

@ -13,6 +13,11 @@ Brief description.
* `<parameter>` - Detailed description of each parameter.
## Step configuration
The following parameters can also be specified as step parameters using the global configuration file:
* `<parameter>`
## Return value
none

View File

@ -1,32 +1,34 @@
#!groovy
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.DefaultValueCache
import com.sap.piper.GitUtils
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsEnvironmentRule
import util.JenkinsLoggingRule
import util.JenkinsReadMavenPomRule
import util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.JenkinsWriteFileRule
import util.Rules
import static org.junit.Assert.assertEquals
class ArtifactSetVersionTest extends BasePipelineTest {
Map dockerParameters
def mavenExecuteScript
Script artifactSetVersionScript
def cpe
def gitUtils
def sshAgentList = []
ExpectedException thrown = ExpectedException.none()
JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
private ExpectedException thrown = ExpectedException.none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsWriteFileRule jwfr = new JenkinsWriteFileRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = Rules
@ -36,9 +38,20 @@ class ArtifactSetVersionTest extends BasePipelineTest {
.around(jscr)
.around(new JenkinsReadMavenPomRule(this, 'test/resources/MavenArtifactVersioning'))
.around(jwfr)
.around(jsr)
.around(jer)
@Before
void init() throws Throwable {
dockerParameters = [:]
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
{ parameters, closure ->
dockerParameters = parameters
closure()
})
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
helper.registerAllowedMethod("sshagent", [List.class, Closure.class], { list, closure ->
sshAgentList = list
@ -46,62 +59,72 @@ class ArtifactSetVersionTest extends BasePipelineTest {
})
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
jscr.setReturnValue("date +'%Y%m%d%H%M%S'", '20180101010203')
jscr.setReturnValue("date --universal +'%Y%m%d%H%M%S'", '20180101010203')
jscr.setReturnValue('git diff --quiet HEAD', 0)
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
artifactSetVersionScript = loadScript("artifactSetVersion.groovy")
binding.setVariable('Jenkins', [instance: [pluginManager: [plugins: [new DockerExecuteTest.PluginMock()]]]])
gitUtils = new GitUtils()
prepareObjectInterceptors(gitUtils)
this.helper.registerAllowedMethod('fileExists', [String.class], {true})
}
@Test
void testVersioning() {
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl')
assertEquals('1.2.3-20180101010203_testCommitId', cpe.getArtifactVersion())
assertEquals('testCommitId', cpe.getGitCommitId())
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
assertEquals('testCommitId', jer.env.getGitCommitId())
assertEquals('mvn versions:set -DnewVersion=1.2.3-20180101010203_testCommitId --file pom.xml', jscr.shell[3])
assertEquals('git add .', jscr.shell[4])
assertEquals ("git commit -m 'update version 1.2.3-20180101010203_testCommitId'", jscr.shell[5])
assertEquals ("git remote set-url origin myGitSshUrl", jscr.shell[6])
assertEquals ("git tag build_1.2.3-20180101010203_testCommitId", jscr.shell[7])
assertEquals ("git push origin build_1.2.3-20180101010203_testCommitId", jscr.shell[8])
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId', jscr.shell[5])
assertEquals('git add .', jscr.shell[6])
assertEquals ("git commit -m 'update version 1.2.3-20180101010203_testCommitId'", jscr.shell[7])
assertEquals ("git remote set-url origin myGitSshUrl", jscr.shell[8])
assertEquals ("git tag build_1.2.3-20180101010203_testCommitId", jscr.shell[9])
assertEquals ("git push origin build_1.2.3-20180101010203_testCommitId", jscr.shell[10])
}
@Test
void testVersioningWithoutCommit() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'maven', commitVersion: false)
assertEquals('1.2.3-20180101010203_testCommitId', jer.env.getArtifactVersion())
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101010203_testCommitId', jscr.shell[5])
}
@Test
void testVersioningCustomGitUserAndEMail() {
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'maven', gitSshUrl: 'myGitSshUrl', gitUserEMail: 'test@test.com', gitUserName: 'test')
assertEquals ('git -c user.email="test@test.com" -c user.name "test" commit -m \'update version 1.2.3-20180101010203_testCommitId\'', jscr.shell[5])
assertEquals ('git -c user.email="test@test.com" -c user.name="test" commit -m \'update version 1.2.3-20180101010203_testCommitId\'', jscr.shell[7])
}
@Test
void testVersioningWithTimestamp() {
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils, buildTool: 'maven', timestamp: '2018')
assertEquals('1.2.3-2018_testCommitId', cpe.getArtifactVersion())
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'maven', timestamp: '2018')
assertEquals('1.2.3-2018_testCommitId', jer.env.getArtifactVersion())
}
@Test
void testVersioningNoBuildTool() {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR buildTool')
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils)
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils)
}
@Test
void testVersioningWithCustomTemplate() {
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils, buildTool: 'maven', versioningTemplate: '${version}-xyz')
assertEquals('1.2.3-xyz', cpe.getArtifactVersion())
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'maven', versioningTemplate: '${version}-xyz')
assertEquals('1.2.3-xyz', jer.env.getArtifactVersion())
}
@Test
void testVersioningWithTypeAppContainer() {
cpe.setArtifactVersion('1.2.3-xyz')
artifactSetVersionScript.call(script: [commonPipelineEnvironment: cpe], juStabGitUtils: gitUtils, buildTool: 'docker', artifactType: 'appContainer', dockerVersionSource: 'appVersion')
assertEquals('1.2.3-xyz', cpe.getArtifactVersion())
jer.env.setArtifactVersion('1.2.3-xyz')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], juStabGitUtils: gitUtils, buildTool: 'docker', artifactType: 'appContainer', dockerVersionSource: 'appVersion')
assertEquals('1.2.3-xyz', jer.env.getArtifactVersion())
assertEquals('1.2.3-xyz', jwfr.files['VERSION'])
}
@ -111,5 +134,4 @@ class ArtifactSetVersionTest extends BasePipelineTest {
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
}
}

View File

@ -10,22 +10,23 @@ import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
import util.Rules
import util.JenkinsStepRule
class ChecksPublishResultsTest extends BasePipelineTest {
Map publisherStepOptions
List archiveStepPatterns
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
def checksPublishResultsScript
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(jsr)
@Before
void init() {
publisherStepOptions = [:]
archiveStepPatterns = []
// prepare checkResultsPublish step
checksPublishResultsScript = loadScript("checksPublishResults.groovy").checksPublishResults
// add handler for generic step call
helper.registerAllowedMethod("step", [Map.class], {
parameters -> publisherStepOptions[parameters.$class] = parameters
@ -37,7 +38,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithDefaultSettings() throws Exception {
checksPublishResultsScript.call()
jsr.step.call()
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published
@ -50,7 +51,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForJavaWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -68,7 +69,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForJavaScriptWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(eslint: true)
jsr.step.call(eslint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -86,7 +87,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishForPythonWithDefaultSettings() throws Exception {
checksPublishResultsScript.call(pylint: true)
jsr.step.call(pylint: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("WarningsPublisher options not set", publisherStepOptions['WarningsPublisher'] != null)
@ -105,7 +106,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothing() throws Exception {
checksPublishResultsScript.call(aggregation: false)
jsr.step.call(aggregation: false)
// ensure nothing is published
assertTrue("AnalysisPublisher options not empty", publisherStepOptions['AnalysisPublisher'] == null)
@ -118,7 +119,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingExplicitFalse() throws Exception {
checksPublishResultsScript.call(pmd: false)
jsr.step.call(pmd: false)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
// ensure nothing else is published
@ -131,7 +132,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingImplicitTrue() throws Exception {
checksPublishResultsScript.call(pmd: [:])
jsr.step.call(pmd: [:])
// ensure pmd is not published
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -139,7 +140,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishNothingExplicitActiveFalse() throws Exception {
checksPublishResultsScript.call(pmd: [active: false])
jsr.step.call(pmd: [active: false])
// ensure pmd is not published
assertTrue("PmdPublisher options not empty", publisherStepOptions['PmdPublisher'] == null)
@ -148,7 +149,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithChangedStepDefaultSettings() throws Exception {
// pmd has been set to active: true in step configuration
checksPublishResultsScript.call(script: [commonPipelineEnvironment: [
jsr.step.call(script: [commonPipelineEnvironment: [
configuration: [steps: [checksPublishResults: [pmd: [active: true]]]]
]])
@ -163,7 +164,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithCustomPattern() throws Exception {
checksPublishResultsScript.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
jsr.step.call(eslint: [pattern: 'my-fancy-file.ext'], pmd: [pattern: 'this-is-not-a-patter.xml'])
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)
@ -180,7 +181,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithArchive() throws Exception {
checksPublishResultsScript.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(archive: true, eslint: true, pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 5)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -192,7 +193,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithPartialArchive() throws Exception {
checksPublishResultsScript.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
jsr.step.call(archive: true, eslint: [archive: false], pmd: true, cpd: true, findbugs: true, checkstyle: true)
assertTrue("ArchivePatterns number not correct", archiveStepPatterns.size() == 4)
assertTrue("ArchivePatterns contains no PMD pattern", archiveStepPatterns.contains('**/target/pmd.xml'))
@ -205,7 +206,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithDefaultThresholds() throws Exception {
checksPublishResultsScript.call(pmd: true)
jsr.step.call(pmd: true)
assertTrue("AnalysisPublisher options not set",
publisherStepOptions['AnalysisPublisher'] != null)
@ -239,7 +240,7 @@ class ChecksPublishResultsTest extends BasePipelineTest {
@Test
void testPublishWithThresholds() throws Exception {
checksPublishResultsScript.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
jsr.step.call(aggregation: [thresholds: [fail: [high: '10']]], pmd: true)
assertTrue("AnalysisPublisher options not set", publisherStepOptions['AnalysisPublisher'] != null)
assertTrue("PmdPublisher options not set", publisherStepOptions['PmdPublisher'] != null)

View File

@ -8,6 +8,8 @@ import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsLoggingRule
import util.Rules
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
@ -17,69 +19,79 @@ class DockerExecuteTest extends BasePipelineTest {
private DockerMock docker
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = RuleChain.outerRule(Rules.getCommonRules(this))
.around(jlr)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(jlr)
.around(jsr)
int whichDockerReturnValue = 0
def bodyExecuted
def cpe
def dockerExecuteScript;
@Before
void init() {
bodyExecuted = false
docker = new DockerMock()
binding.setVariable('docker', docker)
binding.setVariable('Jenkins', [instance: [pluginManager: [plugins: [new PluginMock()]]]])
helper.registerAllowedMethod('sh', [Map.class], {return whichDockerReturnValue})
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
dockerExecuteScript = loadScript('dockerExecute.groovy').dockerExecute
}
@Test
void testExecuteInsideDocker() throws Exception {
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
dockerImage: 'maven:3.5-jdk-8-alpine') {
bodyExecuted = true
}
assertEquals('maven:3.5-jdk-8-alpine', docker.getImageName())
assertTrue(docker.isImagePulled())
assertEquals(' --env http_proxy --env https_proxy --env no_proxy --env HTTP_PROXY --env HTTPS_PROXY --env NO_PROXY', docker.getParameters())
assertEquals('--env http_proxy --env https_proxy --env no_proxy --env HTTP_PROXY --env HTTPS_PROXY --env NO_PROXY', docker.getParameters().trim())
assertTrue(bodyExecuted)
}
@Test
void testExecuteInsideDockerWithParameters() throws Exception {
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
dockerImage: 'maven:3.5-jdk-8-alpine',
dockerOptions: '-it',
dockerVolumeBind: ['my_vol': '/my_vol'],
dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
bodyExecuted = true
}
assertTrue(docker.getParameters().contains(' --env https_proxy '))
assertTrue(docker.getParameters().contains(' --env http_proxy=http://proxy:8000'))
assertTrue(docker.getParameters().contains(' -it'))
assertTrue(docker.getParameters().contains(' --volume my_vol:/my_vol'))
assertTrue(docker.getParameters().contains('--env https_proxy '))
assertTrue(docker.getParameters().contains('--env http_proxy=http://proxy:8000'))
assertTrue(docker.getParameters().contains('-it'))
assertTrue(docker.getParameters().contains('--volume my_vol:/my_vol'))
assertTrue(bodyExecuted)
}
@Test
void testExecuteDockerWithDockerOptionsList() throws Exception {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
dockerImage: 'maven:3.5-jdk-8-alpine',
dockerOptions: ['-it', '--network=my-network'],
dockerEnvVars: ['http_proxy': 'http://proxy:8000']) {
bodyExecuted = true
}
assertTrue(docker.getParameters().contains('--env https_proxy '))
assertTrue(docker.getParameters().contains('--env http_proxy=http://proxy:8000'))
assertTrue(docker.getParameters().contains('-it'))
assertTrue(docker.getParameters().contains('--network=my-network'))
}
@Test
void testDockerNotInstalledResultsInLocalExecution() throws Exception {
whichDockerReturnValue = 1
dockerExecuteScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
dockerImage: 'maven:3.5-jdk-8-alpine',
dockerOptions: '-it',
dockerVolumeBind: ['my_vol': '/my_vol'],

View File

@ -7,21 +7,26 @@ import static org.junit.Assert.assertTrue
import org.junit.rules.RuleChain
import util.Rules
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
class DurationMeasureTest extends BasePipelineTest {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain rules = Rules.getCommonRules(this)
public RuleChain rules = Rules
.getCommonRules(this)
.around(jsr)
.around(jer)
@Test
void testDurationMeasurement() throws Exception {
def cpe = loadScript("commonPipelineEnvironment.groovy").commonPipelineEnvironment
def script = loadScript("durationMeasure.groovy")
def bodyExecuted = false
script.call(script: [commonPipelineEnvironment: cpe], measurementName: 'test') {
jsr.step.call(script: [commonPipelineEnvironment: jer.env], measurementName: 'test') {
bodyExecuted = true
}
assertTrue(cpe.getPipelineMeasurement('test') != null)
assertTrue(jer.env.getPipelineMeasurement('test') != null)
assertTrue(bodyExecuted)
assertJobStatusSuccess()
}

View File

@ -6,37 +6,36 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import util.Rules
import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals
class InfluxWriteDataTest extends BasePipelineTest {
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
Script influxWriteDataScript
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(loggingRule)
.around(jsr)
.around(jer)
Map fileMap = [:]
Map stepMap = [:]
String echoLog = ''
def cpe
public JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(loggingRule)
@Before
void init() throws Exception {
//
// Currently we have dependencies between the tests since
// DefaultValueCache is a singleton which keeps its status
// for all the tests. Depending on the test order we fail.
// As long as this status remains we need:
DefaultValueCache.reset()
//reset stepMap
stepMap = [:]
//reset fileMap
@ -48,20 +47,16 @@ class InfluxWriteDataTest extends BasePipelineTest {
steps : [influxWriteData: [influxServer: 'testInflux']]
]
})
helper.registerAllowedMethod('writeFile', [Map.class],{m -> fileMap[m.file] = m.text})
helper.registerAllowedMethod('step', [Map.class],{m -> stepMap = m})
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
influxWriteDataScript = loadScript("influxWriteData.groovy")
}
@Test
void testInfluxWriteDataWithDefault() throws Exception {
cpe.setArtifactVersion('1.2.3')
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe])
jer.env.setArtifactVersion('1.2.3')
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertTrue(loggingRule.log.contains('Artifact version: 1.2.3'))
@ -79,8 +74,8 @@ class InfluxWriteDataTest extends BasePipelineTest {
@Test
void testInfluxWriteDataNoInflux() throws Exception {
cpe.setArtifactVersion('1.2.3')
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe], influxServer: '')
jer.env.setArtifactVersion('1.2.3')
jsr.step.call(script: [commonPipelineEnvironment: jer.env], influxServer: '')
assertEquals(0, stepMap.size())
@ -93,7 +88,7 @@ class InfluxWriteDataTest extends BasePipelineTest {
@Test
void testInfluxWriteDataNoArtifactVersion() throws Exception {
influxWriteDataScript.call(script: [commonPipelineEnvironment: cpe])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertEquals(0, stepMap.size())
assertEquals(0, fileMap.size())

View File

@ -1,81 +1,114 @@
import hudson.AbortException
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.parser.ParserException
import org.junit.Before
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import org.junit.rules.TemporaryFolder
import org.yaml.snakeyaml.parser.ParserException
import com.lesfurets.jenkins.unit.BasePipelineTest
import hudson.AbortException
import util.JenkinsEnvironmentRule
import util.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.Rules
public class MTABuildTest extends BasePipelineTest {
public class MtaBuildTest extends BasePipelineTest {
def toolMtaValidateCalled = false
def toolJavaValidateCalled = false
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException()
private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(tmp)
.around(jlr)
.around(jscr)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jscr)
.around(jsr)
.around(jer)
private static currentDir
private static newDir
private static mtaYaml
def currentDir
def mtaYaml
@BeforeClass
static void createTestFiles() {
def mtaBuildScript
def cpe
currentDir = "${tmp.getRoot()}"
mtaYaml = tmp.newFile('mta.yaml')
newDir = "$currentDir/newDir"
tmp.newFolder('newDir')
tmp.newFile('newDir/mta.yaml') << defaultMtaYaml()
}
@Before
void init() {
currentDir = tmp.newFolder().toURI().getPath()[0..-2] //omit final '/'
mtaYaml = new File("$currentDir/mta.yaml")
mtaYaml << defaultMtaYaml()
mtaYaml.text = defaultMtaYaml()
helper.registerAllowedMethod('pwd', [], { currentDir } )
helper.registerAllowedMethod('fileExists', [GString.class], { false })
binding.setVariable('PATH', '/usr/bin')
mtaBuildScript = loadScript('mtaBuild.groovy').mtaBuild
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
//
// needs to be after loading the scripts. Here we have a different behaviour
// for usual steps and for steps contained in the shared lib itself.
//
// toolValidate mocked here since we are not interested in testing
// toolValidate here. This is expected to be done in a test class for
// toolValidate.
//
helper.registerAllowedMethod('toolValidate', [Map], { m ->
if(m.tool == 'mta')
toolMtaValidateCalled = true
if(m.tool == 'java')
toolJavaValidateCalled = true
})
}
@Test
void environmentPathTest() {
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
assert jscr.shell[1].contains('PATH=./node_modules/.bin:/usr/bin')
assert jscr.shell.find { c -> c.contains('PATH=./node_modules/.bin:/usr/bin')}
}
@Test
void sedTest() {
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/mta.yaml"$/}
}
@Test
void mtarFilePathFromCommonPipelineEnviromentTest() {
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
buildTarget: 'NEO')
def mtarFilePath = cpe.getMtarFilePath()
def mtarFilePath = jer.env.getMtarFilePath()
assert mtarFilePath == "$currentDir/com.mycompany.northwind.mtar"
}
@ -84,29 +117,22 @@ public class MTABuildTest extends BasePipelineTest {
@Test
void mtaBuildWithSurroundingDirTest() {
def newDirName = 'newDir'
def newDirPath = "$currentDir/$newDirName"
def newDir = new File(newDirPath)
helper.registerAllowedMethod('pwd', [], { newDir } )
newDir.mkdirs()
new File(newDir, 'mta.yaml') << defaultMtaYaml()
def mtarFilePath = jsr.step.call(buildTarget: 'NEO')
helper.registerAllowedMethod('pwd', [], { newDirPath } )
assert jscr.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/}
def mtarFilePath = mtaBuildScript.call(buildTarget: 'NEO')
assert jscr.shell[0] =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" ".*\/newDir\/mta.yaml"$/
assert mtarFilePath == "$currentDir/$newDirName/com.mycompany.northwind.mtar"
assert mtarFilePath == "$newDir/com.mycompany.northwind.mtar"
}
@Test
void mtaJarLocationNotSetTest() {
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
assert jscr.shell[1].contains(' -jar mta.jar --mtar ')
assert jscr.shell.find { c -> c.contains(' -jar mta.jar --mtar ')}
assert jlr.log.contains('[mtaBuild] Using MTA JAR from current working directory.')
}
@ -115,9 +141,9 @@ public class MTABuildTest extends BasePipelineTest {
@Test
void mtaJarLocationAsParameterTest() {
mtaBuildScript.call(mtaJarLocation: '/mylocation/mta', buildTarget: 'NEO')
jsr.step.call(mtaJarLocation: '/mylocation/mta', buildTarget: 'NEO')
assert jscr.shell[1].contains(' -jar /mylocation/mta/mta.jar --mtar ')
assert jscr.shell.find { c -> c.contains(' -jar /mylocation/mta/mta.jar --mtar ')}
assert jlr.log.contains('[mtaBuild] MTA JAR "/mylocation/mta/mta.jar" retrieved from configuration.')
}
@ -129,7 +155,7 @@ public class MTABuildTest extends BasePipelineTest {
mtaYaml.delete()
thrown.expect(FileNotFoundException)
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
}
@ -141,7 +167,7 @@ public class MTABuildTest extends BasePipelineTest {
mtaYaml.text = badMtaYaml()
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
}
@ -153,7 +179,7 @@ public class MTABuildTest extends BasePipelineTest {
mtaYaml.text = noIdMtaYaml()
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
}
@ -163,9 +189,9 @@ public class MTABuildTest extends BasePipelineTest {
binding.setVariable('env', [:])
binding.getVariable('env')['MTA_JAR_LOCATION'] = '/env/mta'
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
assert jscr.shell[1].contains('-jar /env/mta/mta.jar --mtar')
assert jscr.shell.find { c -> c.contains('-jar /env/mta/mta.jar --mtar')}
assert jlr.log.contains('[mtaBuild] MTA JAR "/env/mta/mta.jar" retrieved from environment.')
}
@ -173,48 +199,83 @@ public class MTABuildTest extends BasePipelineTest {
@Test
void mtaJarLocationFromCustomStepConfigurationTest() {
cpe.configuration = [general:[mtaJarLocation: '/general/mta']]
jer.env.configuration = [steps:[mtaBuild:[mtaJarLocation: '/step/mta']]]
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe],
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
buildTarget: 'NEO')
assert jscr.shell[1].contains('-jar /general/mta/mta.jar --mtar')
assert jlr.log.contains('[mtaBuild] MTA JAR "/general/mta/mta.jar" retrieved from configuration.')
assert jscr.shell.find(){ c -> c.contains('-jar /step/mta/mta.jar --mtar')}
assert jlr.log.contains('[mtaBuild] MTA JAR "/step/mta/mta.jar" retrieved from configuration.')
}
@Test
void buildTargetFromParametersTest() {
mtaBuildScript.call(buildTarget: 'NEO')
jsr.step.call(buildTarget: 'NEO')
assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')
assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Test
void buildTargetFromCustomStepConfigurationTest() {
cpe.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
jer.env.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')
assert jscr.shell.find(){ c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Test
void buildTargetFromDefaultStepConfigurationTest() {
cpe.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
jer.env.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
mtaBuildScript.call(script: [commonPipelineEnvironment: cpe])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assert jscr.shell[1].contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')
assert jscr.shell.find { c -> c.contains('java -jar mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void skipValidationInCaseMtarJarFileIsUsedFromWorkingDir() {
jscr.setReturnValue('ls mta.jar', 0)
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assert !toolMtaValidateCalled
}
private defaultMtaYaml() {
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void performValidationInCaseMtarJarFileIsNotUsedFromWorkingDir() {
jscr.setReturnValue('ls mta.jar', 1)
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assert toolMtaValidateCalled
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void toolJavaValidateCalled() {
jsr.step.call(buildTarget: 'NEO')
assert toolJavaValidateCalled
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void toolValidateNotCalledWhenJavaHomeIsUnsetButJavaIsInPath() {
jscr.setReturnValue('which java', 0)
jsr.step.call(buildTarget: 'NEO')
assert !toolJavaValidateCalled
assert jlr.log.contains('Tool validation (java) skipped. JAVA_HOME not set, but java executable in path.')
}
private static defaultMtaYaml() {
return '''
_schema-version: "2.0.0"
ID: "com.mycompany.northwind"

View File

@ -66,4 +66,13 @@ class MavenExecuteTest extends BasePipelineTest {
String mvnCommand = "mvn --global-settings 'globalSettingsFile.xml' -Dmaven.repo.local='m2Path' --settings 'projectSettingsFile.xml' --file 'pom.xml' -o clean install -Dmaven.tests.skip=true"
assertTrue(jscr.shell.contains(mvnCommand))
}
@Test
void testMavenCommandForwardsDockerOptions() throws Exception {
mavenExecuteScript.call(script: [commonPipelineEnvironment: cpe], goals: 'clean install')
assertEquals('maven:3.5-jdk-7', dockerParameters.dockerImage)
assert jscr.shell[0] == 'mvn clean install'
}
}

View File

@ -0,0 +1,500 @@
import hudson.AbortException
import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.BeforeClass
import org.junit.ClassRule
import org.junit.Ignore
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import util.Rules
class NeoDeployTest extends BasePipelineTest {
def toolJavaValidateCalled = false
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException().none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jscr)
.around(jsr)
.around(jer)
def toolNeoValidateCalled = false
private static workspacePath
private static warArchiveName
private static propertiesFileName
private static archiveName
@BeforeClass
static void createTestFiles() {
workspacePath = "${tmp.getRoot()}"
warArchiveName = 'warArchive.war'
propertiesFileName = 'config.properties'
archiveName = 'archive.mtar'
tmp.newFile(warArchiveName) << 'dummy war archive'
tmp.newFile(propertiesFileName) << 'dummy properties file'
tmp.newFile(archiveName) << 'dummy archive'
}
@Before
void init() {
helper.registerAllowedMethod('dockerExecute', [Map, Closure], null)
helper.registerAllowedMethod('fileExists', [String], { s -> return new File(workspacePath, s).exists() })
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
if(l[0].credentialsId == 'myCredentialsId') {
binding.setProperty('username', 'anonymous')
binding.setProperty('password', '********')
} else if(l[0].credentialsId == 'CI_CREDENTIALS_ID') {
binding.setProperty('username', 'defaultUser')
binding.setProperty('password', '********')
}
try {
c()
} finally {
binding.setProperty('username', null)
binding.setProperty('password', null)
}
})
binding.setVariable('env', ['NEO_HOME':'/opt/neo'])
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123']]]
//
// needs to be after loading the scripts. Here we have a different behaviour
// for usual steps and for steps contained in the shared lib itself.
//
// toolValidate mocked here since we are not interested in testing
// toolValidate here. This is expected to be done in a test class for
// toolValidate.
//
helper.registerAllowedMethod('toolValidate', [Map], { m ->
if(m.tool == 'neo')
toolNeoValidateCalled = true
if(m.tool == 'java')
toolJavaValidateCalled = true
})
}
@Test
void straightForwardTestConfigViaConfigProperties() {
jer.env.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
jer.env.configuration = [:]
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/}
}
@Test
void straightForwardTestConfigViaConfiguration() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/}
}
@Test
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
jer.env.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jer.env.configuration = [steps:[neoDeploy: [host: 'configuration-frwk.deploy.host.com',
account: 'configurationFrwkUser123']]]
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'configuration-frwk\.deploy\.host\.com' --account 'configurationFrwkUser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/}
}
@Test
void badCredentialsIdTest() {
thrown.expect(MissingPropertyException)
thrown.expectMessage('No such property: username')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'badCredentialsId'
)
}
@Test
void credentialsIdNotProvidedTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/ }
}
@Test
void neoHomeNotSetTest() {
binding.setVariable('env', [:])
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
assert jscr.shell.find { c -> c.contains('which neo.sh') }
assert jscr.shell.find { c -> c.contains('"neo.sh" deploy-mta') }
assert jlr.log.contains('Using Neo executable from PATH.')
}
@Test
void neoHomeAsParameterTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId',
neoHome: '/etc/neo'
)
assert jscr.shell.find{ c -> c = '"/etc/neo/tools/neo.sh" deploy-mta' }
assert jlr.log.contains('[neoDeploy] Neo executable "/etc/neo/tools/neo.sh" retrieved from configuration.')
}
@Test
void neoHomeFromEnvironmentTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
assert jscr.shell.find { c -> c.contains('"/opt/neo/tools/neo.sh" deploy-mta')}
assert jlr.log.contains('[neoDeploy] Neo executable "/opt/neo/tools/neo.sh" retrieved from environment.')
}
@Test
void neoHomeFromCustomStepConfigurationTest() {
jer.env.configuration = [steps:[neoDeploy: [host: 'test.deploy.host.com', account: 'trialuser123', neoHome: '/step/neo']]]
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName
)
assert jscr.shell.find { c -> c = '"/step/neo/tools/neo.sh" deploy-mta'}
assert jlr.log.contains('[neoDeploy] Neo executable "/step/neo/tools/neo.sh" retrieved from configuration.')
}
@Test
void archiveNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
}
@Test
void wrongArchivePathProvidedTest() {
thrown.expect(AbortException)
thrown.expectMessage('Archive cannot be found')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: 'wrongArchiveName')
}
@Test
void scriptNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
jer.env.configuration = [:]
jsr.step.call(archivePath: archiveName)
}
@Test
void mtaDeployModeTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env], archivePath: archiveName, deployMode: 'mta')
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/}
}
@Test
void warFileParamsDeployModeTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
deployMode: 'warParams',
vmSize: 'lite',
warAction: 'deploy',
archivePath: warArchiveName)
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/}
}
@Test
void warFileParamsDeployModeRollingUpdateTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'rolling-update',
vmSize: 'lite')
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/}
}
@Test
void warPropertiesFileDeployModeTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'lite')
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/}
}
@Test
void warPropertiesFileDeployModeRollingUpdateTest() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'rolling-update',
vmSize: 'lite')
assert jscr.shell.find { c -> c =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/}
}
@Test
void applicationNameNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125'
)
}
@Test
void runtimeNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
runtimeVersion: '2.125')
}
@Test
void runtimeVersionNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
runtime: 'neo-javaee6-wp')
}
@Test
void illegalDeployModeTest() {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'illegalMode',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'lite')
}
@Test
void illegalVMSizeTest() {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'illegalVM')
}
@Test
void illegalWARActionTest() {
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'illegalWARAction',
vmSize: 'lite')
}
@Test
void deployHostProvidedAsDeprecatedParameterTest() {
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
deployHost: "my.deploy.host.com"
)
assert jlr.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.")
}
@Test
void deployAccountProvidedAsDeprecatedParameterTest() {
jer.env.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
host: "my.deploy.host.com",
deployAccount: "myAccount"
)
assert jlr.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.")
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void skipValidationWhenNeoToolsetIsInPathButNeoHomeNotProvidedViaConfigNorEnvironment() {
binding.setVariable('env', [:])
jscr.setReturnValue('which neo.sh', 0)
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert !toolNeoValidateCalled
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void performValidationWhenNeoToolsetIsNotInPathAndNeoHomeNotProvidedViaConfigNorEnvironment() {
binding.setVariable('env', [:])
jscr.setReturnValue('which neo.sh', 1)
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert toolNeoValidateCalled
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void toolJavaValidateCalled() {
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId')
assert toolJavaValidateCalled
}
@Ignore('Tool validation disabled since it does not work properly in conjunction with slaves.')
@Test
void toolValidateSkippedIfJavaHomeNotSetButJavaInPath() {
jscr.setReturnValue('which java', 0)
jsr.step.envProps = [:] // make sure we are not confused by JAVA_HOME in current env props.
jsr.step.call(script: [commonPipelineEnvironment: jer.env],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId')
assert ! toolJavaValidateCalled
assert jlr.log.contains('Skipping tool validate check (java). Java executable in path, but no JAVA_HOME found.')
}
}

View File

@ -1,496 +0,0 @@
import hudson.AbortException
import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsLoggingRule
import util.JenkinsShellCallRule
import util.Rules
class NeoDeploymentTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none()
private TemporaryFolder tmp = new TemporaryFolder()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(tmp)
.around(jlr)
.around(jscr)
def workspacePath
def warArchiveName
def propertiesFileName
def archiveName
def neoDeployScript
def cpe
@Before
void init() {
workspacePath = "${tmp.newFolder("workspace").toURI().getPath()}"
warArchiveName = 'warArchive.war'
propertiesFileName = 'config.properties'
archiveName = "archive.mtar"
helper.registerAllowedMethod('dockerExecute', [Map, Closure], null)
helper.registerAllowedMethod('fileExists', [String], { s -> return new File(workspacePath, s).exists() })
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
helper.registerAllowedMethod('withCredentials', [List, Closure], { l, c ->
if(l[0].credentialsId == 'myCredentialsId') {
binding.setProperty('username', 'anonymous')
binding.setProperty('password', '********')
} else if(l[0].credentialsId == 'CI_CREDENTIALS_ID') {
binding.setProperty('username', 'defaultUser')
binding.setProperty('password', '********')
}
try {
c()
} finally {
binding.setProperty('username', null)
binding.setProperty('password', null)
}
})
binding.setVariable('env', [:])
neoDeployScript = loadScript("neoDeploy.groovy").neoDeploy
cpe = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
}
@Test
void straightForwardTestConfigViaConfigProperties() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void straightForwardTestConfigViaConfiguration() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
cpe.configuration.put('steps', [neoDeploy: [host: 'test.deploy.host.com',
account: 'trialuser123']])
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
//configuration via configurationFramekwork superseds.
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
cpe.configuration.put('steps', [neoDeploy: [host: 'configuration-frwk.deploy.host.com',
account: 'configurationFrwkUser123']])
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId'
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'configuration-frwk\.deploy\.host\.com' --account 'configurationFrwkUser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void badCredentialsIdTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
thrown.expect(MissingPropertyException)
thrown.expectMessage('No such property: username')
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
neoCredentialsId: 'badCredentialsId'
)
}
@Test
void credentialsIdNotProvidedTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void neoHomeNotSetTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName
)
assert jscr.shell[0] =~ /#!\/bin\/bash "neo.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("Using Neo executable from PATH.")
}
@Test
void neoHomeAsParameterTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
neoCredentialsId: 'myCredentialsId',
neoHome: '/etc/neo'
)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
}
@Test
void archiveNotProvidedTest() {
thrown.expect(Exception)
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe])
}
@Test
void wrongArchivePathProvidedTest() {
thrown.expect(AbortException)
thrown.expectMessage("Archive cannot be found")
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName)
}
@Test
void scriptNotProvidedTest() {
new File(workspacePath, archiveName) << "dummy archive"
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
neoDeployScript.call(archivePath: archiveName)
}
@Test
void mtaDeployModeTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe], archivePath: archiveName, deployMode: 'mta')
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void warFileParamsDeployModeTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, warArchiveName) << "dummy war archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
deployMode: 'warParams',
vmSize: 'lite',
warAction: 'deploy',
archivePath: warArchiveName)
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void warFileParamsDeployModeRollingUpdateTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, warArchiveName) << "dummy war archive"
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'rolling-update',
vmSize: 'lite')
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void warPropertiesFileDeployModeTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, warArchiveName) << "dummy war archive"
new File(workspacePath, propertiesFileName) << "dummy properties file"
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'lite')
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void warPropertiesFileDeployModeRollingUpdateTest() {
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
new File(workspacePath, warArchiveName) << "dummy war archive"
new File(workspacePath, propertiesFileName) << "dummy properties file"
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warPropertiesFile',
propertiesFile: propertiesFileName,
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'rolling-update',
vmSize: 'lite')
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
}
@Test
void applicationNameNotProvidedTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR applicationName')
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warParams',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125'
)
}
@Test
void runtimeNotProvidedTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
runtimeVersion: '2.125')
}
@Test
void runtimeVersionNotProvidedTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
applicationName: 'testApp',
deployMode: 'warParams',
runtime: 'neo-javaee6-wp')
}
@Test
void illegalDeployModeTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid deployMode = 'illegalMode'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'illegalMode',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'lite')
}
@Test
void illegalVMSizeTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid vmSize = 'illegalVM'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'deploy',
vmSize: 'illegalVM')
}
@Test
void illegalWARActionTest() {
new File(workspacePath, warArchiveName) << "dummy war archive"
thrown.expect(Exception)
thrown.expectMessage("[neoDeploy] Invalid warAction = 'illegalWARAction'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: warArchiveName,
deployMode: 'warParams',
applicationName: 'testApp',
runtime: 'neo-javaee6-wp',
runtimeVersion: '2.125',
warAction: 'illegalWARAction',
vmSize: 'lite')
}
@Test
void deployHostProvidedAsDeprecatedParameterTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
deployHost: "my.deploy.host.com"
)
assert jlr.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.")
}
@Test
void deployAccountProvidedAsDeprecatedParameterTest() {
new File(workspacePath, archiveName) << "dummy archive"
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
archivePath: archiveName,
host: "my.deploy.host.com",
deployAccount: "myAccount"
)
assert jlr.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.")
}
}

View File

@ -9,24 +9,24 @@ import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsReadYamlRule
import util.JenkinsStepRule
class PipelineExecuteTest extends BasePipelineTest {
private ExpectedException thrown = new ExpectedException().none()
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jsr)
def pipelinePath
def checkoutParameters = [:]
def load
def pipelineExecuteScript
@Before
void init() {
pipelinePath = null
checkoutParameters.clear()
load = null
@ -39,15 +39,12 @@ class PipelineExecuteTest extends BasePipelineTest {
checkoutParameters.path = m.extensions[0].sparseCheckoutPaths[0].path
})
helper.registerAllowedMethod('load', [String], { s -> load = s })
pipelineExecuteScript = loadScript("pipelineExecute.groovy").pipelineExecute
}
@Test
void straightForwardTest() {
pipelineExecuteScript.call(repoUrl: "https://test.com/myRepo.git")
jsr.step.call(repoUrl: "https://test.com/myRepo.git")
assert load == "Jenkinsfile"
assert checkoutParameters.branch == 'master'
assert checkoutParameters.repoUrl == "https://test.com/myRepo.git"
@ -58,8 +55,7 @@ class PipelineExecuteTest extends BasePipelineTest {
@Test
void parameterizeTest() {
pipelineExecuteScript.call(repoUrl: "https://test.com/anotherRepo.git",
jsr.step.call(repoUrl: "https://test.com/anotherRepo.git",
branch: 'feature',
path: 'path/to/Jenkinsfile',
credentialsId: 'abcd1234')
@ -74,10 +70,9 @@ class PipelineExecuteTest extends BasePipelineTest {
@Test
void noRepoUrlTest() {
thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR repoUrl")
pipelineExecuteScript.call()
jsr.step.call()
}
}

View File

@ -1,39 +0,0 @@
import com.lesfurets.jenkins.unit.global.lib.SourceRetriever
import groovy.transform.CompileStatic
import groovy.transform.Immutable
/**
* Retrieves the shared lib sources of the current project which are expected to be
* at the default location &quot;./vars&quot;.
*/
@Immutable
@CompileStatic
class ProjectSource implements SourceRetriever {
String sourceURL
/*
* None of the parameters provided in the signature are used in the use-case of that retriever.
*/
@Override
List<URL> retrieve(String repository, String branch, String targetPath) {
def sourceDir = new File(sourceURL)
if (sourceDir.exists()) {
return [sourceDir.getAbsoluteFile().toURI().toURL()]
}
throw new IllegalStateException("Directory $sourceDir.path does not exists")
}
static ProjectSource projectSource(String sourceDir = '.') {
new ProjectSource(sourceDir)
}
@Override
String toString() {
return "${getClass().getSimpleName()}{" +
"sourceURL='" + sourceURL + '\'' +
'}'
}
}

View File

@ -7,24 +7,26 @@ import org.yaml.snakeyaml.Yaml
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.Rules
import util.JenkinsStepRule
import util.JenkinsEnvironmentRule
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull
class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
def usedConfigFile
def setupCommonPipelineEnvironmentScript
def commonPipelineEnvironment
private JenkinsStepRule jsr = new JenkinsStepRule(this)
private JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public RuleChain rules = Rules.getCommonRules(this)
public RuleChain rules = Rules
.getCommonRules(this)
.around(jsr)
.around(jer)
@Before
void init() {
def examplePipelineConfig = new File('test/resources/test_pipeline_config.yml').text
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
@ -32,26 +34,21 @@ class SetupCommonPipelineEnvironmentTest extends BasePipelineTest {
if(parameters.text) {
return yamlParser.load(parameters.text)
}
usedConfigFile = parameters.file
return yamlParser.load(examplePipelineConfig)
})
helper.registerAllowedMethod("fileExists", [String], { String path ->
return path.endsWith('.pipeline/config.yml')
})
setupCommonPipelineEnvironmentScript = loadScript("setupCommonPipelineEnvironment.groovy").setupCommonPipelineEnvironment
commonPipelineEnvironment = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
}
@Test
void testIsConfigurationAvailable() throws Exception {
setupCommonPipelineEnvironmentScript.call(script: [commonPipelineEnvironment: commonPipelineEnvironment])
jsr.step.call(script: [commonPipelineEnvironment: jer.env])
assertEquals('.pipeline/config.yml', usedConfigFile)
assertNotNull(commonPipelineEnvironment.configuration)
assertEquals('develop', commonPipelineEnvironment.configuration.general.productiveBranch)
assertEquals('my-maven-docker', commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
assertNotNull(jer.env.configuration)
assertEquals('develop', jer.env.configuration.general.productiveBranch)
assertEquals('my-maven-docker', jer.env.configuration.steps.mavenExecute.dockerImage)
}
}

View File

@ -13,185 +13,166 @@ import org.junit.rules.TemporaryFolder
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsLoggingRule
import util.JenkinsStepRule
import util.Rules
class ToolValidateTest extends BasePipelineTest {
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
private ExpectedException thrown = new ExpectedException().none()
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules.getCommonRules(this)
.around(thrown)
.around(jlr)
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(thrown)
.around(jlr)
.around(jsr)
private static home
private toolValidateScript
@BeforeClass
static void createTestFiles() {
home = "${tmp.getRoot()}"
tmp.newFile('mta.jar')
}
@Before
void init() {
binding.setVariable('JAVA_HOME', home)
toolValidateScript = loadScript('toolValidate.groovy').toolValidate
}
@Test
void nullHomeTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'home' can not be null or empty.")
toolValidateScript.call(tool: 'java', home: null)
jsr.step.call(tool: 'java', home: null)
}
@Test
void emptyHomeTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'home' can not be null or empty.")
toolValidateScript.call(tool: 'java', home: '')
jsr.step.call(tool: 'java', home: '')
}
@Test
void nullToolTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
toolValidateScript.call(tool: null)
jsr.step.call(tool: null)
}
@Test
void emptyToolTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'tool' can not be null or empty.")
toolValidateScript.call(tool: '')
jsr.step.call(tool: '')
}
@Test
void invalidToolTest() {
thrown.expect(AbortException)
thrown.expectMessage("The tool 'test' is not supported.")
toolValidateScript.call(tool: 'test', home: home)
jsr.step.call(tool: 'test', home: home)
}
@Test
void unableToValidateJavaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of Java failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(tool: 'java', home: home)
}
@Test
void unableToValidateMtaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of SAP Multitarget Application Archive Builder failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
}
@Test
void unableToValidateNeoTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of SAP Cloud Platform Console Client failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', home: home)
}
@Test
void unableToValidateCmTest() {
thrown.expect(AbortException)
thrown.expectMessage('The validation of Change Management Command Line Interface failed.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getNoVersion(m) })
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
script.execute()
}
@Test
void validateIncompatibleVersionJavaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The installed version of Java is 1.7.0.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(tool: 'java', home: home)
}
@Test
void validateIncompatibleVersionMtaTest() {
thrown.expect(AbortException)
thrown.expectMessage('The installed version of SAP Multitarget Application Archive Builder is 1.0.5.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
}
@Test
void validateNeoIncompatibleVersionTest() {
thrown.expect(AbortException)
thrown.expectMessage('The installed version of SAP Cloud Platform Console Client is 1.126.51.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', home: home)
}
@Test
void validateCmIncompatibleVersionTest() {
thrown.expect(AbortException)
thrown.expectMessage('The installed version of Change Management Command Line Interface is 0.0.0.')
helper.registerAllowedMethod('sh', [Map], { Map m -> getIncompatibleVersion(m) })
binding.setVariable('tool', 'cm')
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
}
@Test
void validateJavaTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'java', home: home)
jsr.step.call(tool: 'java', home: home)
assert jlr.log.contains('[toolValidate] Validating Java version 1.8.0 or compatible version.')
assert jlr.log.contains('[toolValidate] Java version 1.8.0 is installed.')
@ -199,10 +180,9 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateMtaTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'mta', home: home)
jsr.step.call(tool: 'mta', home: home)
assert jlr.log.contains('[toolValidate] Validating SAP Multitarget Application Archive Builder version 1.0.6 or compatible version.')
assert jlr.log.contains('[toolValidate] SAP Multitarget Application Archive Builder version 1.0.6 is installed.')
@ -210,10 +190,9 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateNeoTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'neo', home: home)
jsr.step.call(tool: 'neo', home: home)
assert jlr.log.contains('[toolValidate] Validating SAP Cloud Platform Console Client version 3.39.10 or compatible version.')
assert jlr.log.contains('[toolValidate] SAP Cloud Platform Console Client version 3.39.10 is installed.')
@ -221,21 +200,19 @@ class ToolValidateTest extends BasePipelineTest {
@Test
void validateCmTest() {
helper.registerAllowedMethod('sh', [Map], { Map m -> getVersion(m) })
toolValidateScript.call(tool: 'cm', home: home)
jsr.step.call(tool: 'cm', home: home)
assert jlr.log.contains('[toolValidate] Validating Change Management Command Line Interface version 0.0.1 or compatible version.')
assert jlr.log.contains('[toolValidate] Change Management Command Line Interface version 0.0.1 is installed.')
}
private getNoVersion(Map m) {
private getNoVersion(Map m) {
throw new AbortException('script returned exit code 127')
}
private getVersion(Map m) {
if(m.script.contains('java -version')) {
return '''openjdk version \"1.8.0_121\"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13)
@ -252,7 +229,6 @@ class ToolValidateTest extends BasePipelineTest {
}
private getIncompatibleVersion(Map m) {
if(m.script.contains('java -version')) {
return '''openjdk version \"1.7.0_121\"
OpenJDK Runtime Environment (build 1.7.0_121-8u121-b13-1~bpo8+1-b13)
@ -268,4 +244,3 @@ class ToolValidateTest extends BasePipelineTest {
}
}
}

View File

@ -4,6 +4,8 @@ import groovy.test.GroovyAssert
import org.junit.Assert
import org.junit.Test
import static org.hamcrest.Matchers.*
class ConfigurationHelperTest {
private static getConfiguration() {
@ -15,6 +17,7 @@ class ConfigurationHelperTest {
void testGetProperty() {
def configuration = new ConfigurationHelper(getConfiguration())
Assert.assertEquals('maven:3.2-jdk-8-onbuild', configuration.getConfigProperty('dockerImage'))
Assert.assertEquals('maven:3.2-jdk-8-onbuild', configuration.getConfigProperty('dockerImage', 'default'))
Assert.assertEquals('default', configuration.getConfigProperty('something', 'default'))
Assert.assertTrue(configuration.isPropertyDefined('dockerImage'))
Assert.assertFalse(configuration.isPropertyDefined('something'))
@ -27,6 +30,12 @@ class ConfigurationHelperTest {
Assert.assertFalse(configuration.isPropertyDefined('something'))
}
@Test
void testIsPropertyDefinedWithInteger() {
def configuration = new ConfigurationHelper([dockerImage: 3])
Assert.assertTrue(configuration.isPropertyDefined('dockerImage'))
}
@Test
void testGetMandatoryProperty() {
def configuration = new ConfigurationHelper(getConfiguration())
@ -35,4 +44,32 @@ class ConfigurationHelperTest {
GroovyAssert.shouldFail { configuration.getMandatoryProperty('something') }
}
@Test
void testConfigurationLoaderWithDefaults() {
Map config = new ConfigurationHelper([property1: '27']).use()
// asserts
Assert.assertThat(config, hasEntry('property1', '27'))
}
@Test
void testConfigurationLoaderWithCustomSettings() {
Map config = new ConfigurationHelper([property1: '27'])
.mixin([property1: '41'])
.use()
// asserts
Assert.assertThat(config, hasEntry('property1', '41'))
}
@Test
void testConfigurationLoaderWithFilteredCustomSettings() {
Set filter = ['property2']
Map config = new ConfigurationHelper([property1: '27'])
.mixin([property1: '41', property2: '28', property3: '29'], filter)
.use()
// asserts
Assert.assertThat(config, hasEntry('property1', '27'))
Assert.assertThat(config, hasEntry('property2', '28'))
Assert.assertThat(config, not(hasKey('property3')))
}
}

View File

@ -1,17 +1,25 @@
package com.sap.piper
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import com.lesfurets.jenkins.unit.BasePipelineTest
import util.JenkinsResetDefaultCacheRule
class ConfigurationMergerTest {
@Rule
public JenkinsResetDefaultCacheRule resetDefaultValueCacheRule = new JenkinsResetDefaultCacheRule()
@Test
void testMerge(){
Map defaults = [dockerImage: 'mvn']
Map parameters = [goals: 'install', flags: '']
List parameterKeys = ['flags']
Set parameterKeys = ['flags']
Map configuration = [flags: '-B']
List configurationKeys = ['flags']
Set configurationKeys = ['flags']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
Assert.assertEquals('mvn', merged.dockerImage)
Assert.assertNull(merged.goals)
@ -22,7 +30,7 @@ class ConfigurationMergerTest {
void testMergeParameterWithDefault(){
Map defaults = [nonErpDestinations: []]
Map parameters = [nonErpDestinations: null]
List parameterKeys = ['nonErpDestinations']
Set parameterKeys = ['nonErpDestinations']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, defaults)
Assert.assertEquals([], merged.nonErpDestinations)
}
@ -31,9 +39,9 @@ class ConfigurationMergerTest {
void testMergeCustomPipelineValues(){
Map defaults = [dockerImage: 'mvn']
Map parameters = [goals: 'install', flags: '']
List parameterKeys = ['flags']
Set parameterKeys = ['flags']
Map configuration = [flags: '-B']
List configurationKeys = ['flags']
Set configurationKeys = ['flags']
Map pipelineDataMap = [artifactVersion: '1.2.3', flags: 'test']
Map merged = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, configuration, configurationKeys, defaults)
Assert.assertEquals('', merged.flags)
@ -44,9 +52,9 @@ class ConfigurationMergerTest {
void testMergeDeepStructure(){
Map defaults = [fruits: [apples: 1, oranges: 10, bananaaas: 0]]
Map configuration = [fruits: [bananaaas: 50, cucumbers: 1000]]
List configurationKeys = ['fruits']
Set configurationKeys = ['fruits']
Map parameters = [fruits: [apples: 18], veggie: []]
List parameterKeys = ['fruits']
Set parameterKeys = ['fruits']
Map merged = ConfigurationMerger.merge(parameters, parameterKeys, configuration, configurationKeys, defaults)
Assert.assertEquals(50, merged.fruits.bananaaas)
Assert.assertEquals(18, merged.fruits.apples)
@ -54,4 +62,14 @@ class ConfigurationMergerTest {
Assert.assertEquals(1000, merged.fruits.cucumbers)
Assert.assertEquals(null, merged.veggie)
}
@Test
void testReadConfigInsideMerge() {
DefaultValueCache.createInstance([steps:[myStep:[overwrite: 'x', defaultKey1:'defaultValue1']]])
def config = [commonPipelineEnvironment: [configuration: [steps:[myStep:[overwrite: 'y', key1:'value1']]]]]
def mergeResult = ConfigurationMerger.merge(config, "myStep", [:], (Set)[], [:], (Set)['overwrite', 'key1'])
Assert.assertEquals('y', mergeResult.overwrite)
Assert.assertEquals('defaultValue1', mergeResult.defaultKey1)
Assert.assertEquals('value1', mergeResult.key1)
}
}

View File

@ -6,12 +6,12 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.JenkinsReadMavenPomRule
import util.JenkinsShellCallRule
import util.MockHelper
import util.Rules
import util.SharedLibraryCreator
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNull
class GitUtilsTest extends BasePipelineTest {
@ -27,6 +27,7 @@ class GitUtilsTest extends BasePipelineTest {
void init() throws Exception {
gitUtils = new GitUtils()
prepareObjectInterceptors(gitUtils)
gitUtils.fileExists = MockHelper
jscr.setReturnValue('git rev-parse HEAD', 'testCommitId')
}
@ -39,9 +40,14 @@ class GitUtilsTest extends BasePipelineTest {
@Test
void testGetGitCommitId() {
this.helper.registerAllowedMethod('fileExists', [String.class], {true})
assertEquals('testCommitId', gitUtils.getGitCommitIdOrNull())
}
assertEquals('testCommitId', gitUtils.getGitCommitId())
@Test
void testGetGitCommitIdNotAGitRepo() {
this.helper.registerAllowedMethod('fileExists', [String.class], {false})
assertNull(gitUtils.getGitCommitIdOrNull())
}
}

View File

@ -0,0 +1,240 @@
package com.sap.piper
import org.junit.Before
import org.junit.ClassRule
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import org.junit.rules.TemporaryFolder
import org.yaml.snakeyaml.Yaml
import com.lesfurets.jenkins.unit.BasePipelineTest
import groovy.json.JsonSlurper
import hudson.AbortException
import util.JenkinsEnvironmentRule
import util.Rules
class MtaUtilsTest extends BasePipelineTest {
private static srcPackageJson = 'test/resources/MtaUtils/package.json'
private static mtaTemplate = 'resources/template_mta.yml'
private static data
private static String generatedFile
private static String targetMtaDescriptor
private File badJson
private mtaUtils
@Rule
public JenkinsEnvironmentRule jer = new JenkinsEnvironmentRule(this)
@Rule
public ExpectedException thrown= ExpectedException.none();
@ClassRule
public static TemporaryFolder tmp = new TemporaryFolder()
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(jer)
void prepareObjectInterceptors(object) {
object.metaClass.invokeMethod = helper.getMethodInterceptor()
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
}
@Before
void init() {
targetMtaDescriptor = "${tmp.getRoot()}/generated_mta.yml"
def script = new Object()
mtaUtils = new MtaUtils(script)
prepareObjectInterceptors(script)
this.helper.registerAllowedMethod('readJSON', [Map], { Map parameters ->
return new JsonSlurper().parse(new File(parameters.file))
})
this.helper.registerAllowedMethod('libraryResource', [Map], { Map parameters ->
new Yaml().load(new File(mtaTemplate).text)
})
this.helper.registerAllowedMethod('readYaml', [], {
return new Yaml().load(new FileReader(mtaTemplate))
})
this.helper.registerAllowedMethod('writeYaml', [Map], { Map parameters ->
generatedFile = parameters.file
data = parameters.data
})
this.helper.registerAllowedMethod('fileExists', [String.class], { true })
}
@Test
void testStraightForward(){
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, targetMtaDescriptor, 'testAppName')
assert data.ID == 'com.mycompany.northwind'
assert data.version == '1.0.3'
assert data.modules.name[0] == 'testAppName'
assert data.modules.parameters.version[0] == '1.0.3-${timestamp}'
}
@Test
void testSrcPackageJsonEmpty() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'srcPackageJson' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson('', targetMtaDescriptor, 'testApplicationName')
}
@Test
void testSrcPackageJsonNull() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'srcPackageJson' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson(null, targetMtaDescriptor, 'testApplicationName')
}
@Test
void testTargetMtaDescriptorEmpty() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'targetMtaDescriptor' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, '', 'testApplicationName')
}
@Test
void testTargetMtaDescriptorNull() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'targetMtaDescriptor' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, null, 'testApplicationName')
}
@Test
void testApplicationNameEmpty() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'applicationName' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, targetMtaDescriptor, '')
}
@Test
void testApplicationNameNull() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'applicationName' can not be null or empty.")
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, targetMtaDescriptor, null)
}
@Test
void testMissingNameInJson() {
badJson = tmp.newFile('missingName.json')
badJson.text = missingNameInJson()
badJson.dump()
thrown.expect(AbortException)
thrown.expectMessage("'name' not set in the given package.json.")
mtaUtils.generateMtaDescriptorFromPackageJson(badJson.absolutePath, targetMtaDescriptor, 'testApplicationName')
}
@Test
void testEmptyNameInJson() {
badJson = tmp.newFile('emptyName.json')
badJson.text = emptyNameInJson()
badJson.dump()
thrown.expect(AbortException)
thrown.expectMessage("'name' not set in the given package.json.")
mtaUtils.generateMtaDescriptorFromPackageJson(badJson.absolutePath, targetMtaDescriptor, 'testApplicationName')
}
@Test
void testMissingVersionInJson() {
badJson = tmp.newFile('missingVersion.json')
badJson.text = missingVersionInJson()
badJson.dump()
thrown.expect(AbortException)
thrown.expectMessage("'version' not set in the given package.json.")
mtaUtils.generateMtaDescriptorFromPackageJson(badJson.absolutePath, targetMtaDescriptor, 'testApplicationName')
}
@Test
void testEmptyVersionInJson() {
badJson = tmp.newFile('emptyVersion.json')
badJson.text = emptyVersionInJson()
badJson.dump()
thrown.expect(AbortException)
thrown.expectMessage("'version' not set in the given package.json.")
mtaUtils.generateMtaDescriptorFromPackageJson(badJson.absolutePath, targetMtaDescriptor, 'testApplicationName')
}
@Test
void testFileGenerated() {
mtaUtils.generateMtaDescriptorFromPackageJson(srcPackageJson, targetMtaDescriptor, 'testApplicationName')
assert generatedFile.equals(targetMtaDescriptor)
}
private missingNameInJson() {
return '''
{
"version": "1.0.3",
"description": "Webshop application for test purposes",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "^1.3.17"
}
}
'''
}
private emptyNameInJson() {
return '''
{
"name": "",
"version": "1.0.3",
"description": "Webshop application for test purposes",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "^1.3.17"
}
}
'''
}
private missingVersionInJson() {
return '''
{
"name": "com.mycompany.northwind",
"description": "Webshop application for test purposes",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "^1.3.17"
}
}
'''
}
private emptyVersionInJson() {
return '''
{
"name": "com.mycompany.northwind",
"version": "",
"description": "Webshop application for test purposes",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "^1.3.17"
}
}
'''
}
}

View File

@ -11,10 +11,13 @@ import util.JenkinsShellCallRule
import util.Rules
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
class MavenArtifactVersioningTest extends BasePipelineTest{
Map dockerParameters
def mavenExecuteScript
def commonPipelineEnvironment
MavenArtifactVersioning av
JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
@ -24,7 +27,18 @@ class MavenArtifactVersioningTest extends BasePipelineTest{
public RuleChain ruleChain = Rules.getCommonRules(this).around(jscr).around(thrown).around(new JenkinsReadMavenPomRule(this, 'test/resources/MavenArtifactVersioning'))
@Before
public void init() {
void init() {
dockerParameters = [:]
helper.registerAllowedMethod("dockerExecute", [Map.class, Closure.class],
{ parameters, closure ->
dockerParameters = parameters
closure()
})
mavenExecuteScript = loadScript("mavenExecute.groovy").mavenExecute
commonPipelineEnvironment = loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
prepareObjectInterceptors(this)
}
@ -33,19 +47,17 @@ class MavenArtifactVersioningTest extends BasePipelineTest{
av = new MavenArtifactVersioning(this, [filePath: 'pom.xml'])
assertEquals('1.2.3', av.getVersion())
av.setVersion('1.2.3-20180101')
assertEquals('mvn versions:set -DnewVersion=1.2.3-20180101 --file pom.xml', jscr.shell[0])
assertEquals('mvn --file \'pom.xml\' versions:set -DnewVersion=1.2.3-20180101', jscr.shell[0])
}
@Test
void testVersioningCustomFilePathSnapshot() {
av = new MavenArtifactVersioning(this, [filePath: 'snapshot/pom.xml'])
assertEquals('1.2.3', av.getVersion())
av.setVersion('1.2.3-20180101')
assertEquals('mvn versions:set -DnewVersion=1.2.3-20180101 --file snapshot/pom.xml', jscr.shell[0])
assertEquals('mvn --file \'snapshot/pom.xml\' versions:set -DnewVersion=1.2.3-20180101', jscr.shell[0])
}
void prepareObjectInterceptors(object) {
object.metaClass.invokeMethod = helper.getMethodInterceptor()
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()

View File

@ -0,0 +1,28 @@
package util
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
class JenkinsEnvironmentRule implements TestRule {
final BasePipelineTest testInstance
def env
JenkinsEnvironmentRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
env = testInstance.loadScript('commonPipelineEnvironment.groovy').commonPipelineEnvironment
base.evaluate()
}
}
}
}

View File

@ -0,0 +1,32 @@
package util
import com.lesfurets.jenkins.unit.BasePipelineTest
import java.beans.Introspector
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
class JenkinsStepRule implements TestRule {
final BasePipelineTest testInstance
def step
JenkinsStepRule(BasePipelineTest testInstance) {
this.testInstance = testInstance
}
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
def testClassName = testInstance.getClass().getSimpleName()
def stepName = Introspector.decapitalize(testClassName.replaceAll('Test$', ''))
this.step = testInstance.loadScript("${stepName}.groovy")
base.evaluate()
}
}
}
}

View File

@ -0,0 +1,10 @@
{
"name": "com.mycompany.northwind",
"version": "1.0.3",
"description": "Webshop application for test purposes",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "^1.3.17"
}
}

View File

@ -1,68 +1,54 @@
import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger
import com.sap.piper.ConfigurationHelper
import com.sap.piper.GitUtils
import com.sap.piper.Utils
import com.sap.piper.versioning.ArtifactVersioning
import groovy.transform.Field
import groovy.text.SimpleTemplateEngine
@Field String STEP_NAME = 'artifactSetVersion'
@Field Set STEP_CONFIG_KEYS = [
'artifactType',
'buildTool',
'commitVersion',
'dockerVersionSource',
'filePath',
'gitCredentialsId',
'gitUserEMail',
'gitUserName',
'gitSshUrl',
'tagPrefix',
'timestamp',
'timestampTemplate',
'versioningTemplate'
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus('gitCommitId')
def call(Map parameters = [:]) {
def stepName = 'artifactSetVersion'
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def gitUtils = parameters.juStabGitUtils
if (gitUtils == null) {
gitUtils = new GitUtils()
}
if (sh(returnStatus: true, script: 'git diff --quiet HEAD') != 0)
error "[${stepName}] Files in the workspace have been changed previously - aborting ${stepName}"
if (fileExists('.git')) {
if (sh(returnStatus: true, script: 'git diff --quiet HEAD') != 0)
error "[${STEP_NAME}] Files in the workspace have been changed previously - aborting ${STEP_NAME}"
}
def script = parameters.script
if (script == null)
script = [commonPipelineEnvironment: commonPipelineEnvironment]
prepareDefaultValues script: script
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)
List parameterKeys = [
'artifactType',
'buildTool',
'dockerVersionSource',
'filePath',
'gitCommitId',
'gitCredentialsId',
'gitUserEMail',
'gitUserName',
'gitSshUrl',
'tagPrefix',
'timestamp',
'timestampTemplate',
'versioningTemplate'
]
Map pipelineDataMap = [
gitCommitId: gitUtils.getGitCommitId()
]
List stepConfigurationKeys = [
'artifactType',
'buildTool',
'dockerVersionSource',
'filePath',
'gitCredentialsId',
'gitUserEMail',
'gitUserName',
'gitSshUrl',
'tagPrefix',
'timestamp',
'timestampTemplate',
'versioningTemplate'
]
Map configuration = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, stepConfiguration, stepConfigurationKeys, stepDefaults)
// load default & individual configuration
Map configuration = ConfigurationHelper
.loadStepDefaults(this)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixin(gitCommitId: gitUtils.getGitCommitIdOrNull())
.mixin(parameters, PARAMETER_KEYS)
.use()
def utils = new Utils()
def buildTool = utils.getMandatoryParameter(configuration, 'buildTool')
@ -78,7 +64,7 @@ def call(Map parameters = [:]) {
//replace + sign if available since + is not allowed in a Docker tag
newVersion = script.commonPipelineEnvironment.getArtifactVersion().replace('+', '_')
else
error ("[${stepName}] No artifact version available for 'dockerVersionSource: appVersion' -> executeBuild needs to run for the application artifact first to set the artifactVersion for the application artifact.'")
error ("[${STEP_NAME}] No artifact version available for 'dockerVersionSource: appVersion' -> executeBuild needs to run for the application artifact first to set the artifactVersion for the application artifact.'")
} else {
def currentVersion = artifactVersioning.getVersion()
@ -94,29 +80,30 @@ def call(Map parameters = [:]) {
artifactVersioning.setVersion(newVersion)
sh 'git add .'
def gitCommitId
sshagent([configuration.gitCredentialsId]) {
def gitUserMailConfig = ''
if (configuration.gitUserName && configuration.gitUserEMail)
gitUserMailConfig = "-c user.email=\"${configuration.gitUserEMail}\" -c user.name \"${configuration.gitUserName}\""
if (configuration.commitVersion) {
sh 'git add .'
try {
sh "git ${gitUserMailConfig} commit -m 'update version ${newVersion}'"
} catch (e) {
error "[${stepName}]git commit failed: ${e}"
sshagent([configuration.gitCredentialsId]) {
def gitUserMailConfig = ''
if (configuration.gitUserName && configuration.gitUserEMail)
gitUserMailConfig = "-c user.email=\"${configuration.gitUserEMail}\" -c user.name=\"${configuration.gitUserName}\""
try {
sh "git ${gitUserMailConfig} commit -m 'update version ${newVersion}'"
} catch (e) {
error "[${STEP_NAME}]git commit failed: ${e}"
}
sh "git remote set-url origin ${configuration.gitSshUrl}"
sh "git tag ${configuration.tagPrefix}${newVersion}"
sh "git push origin ${configuration.tagPrefix}${newVersion}"
gitCommitId = gitUtils.getGitCommitIdOrNull()
}
sh "git remote set-url origin ${configuration.gitSshUrl}"
sh "git tag ${configuration.tagPrefix}${newVersion}"
sh "git push origin ${configuration.tagPrefix}${newVersion}"
gitCommitId = gitUtils.getGitCommitId()
}
if(buildTool == 'docker' && configuration.artifactType == 'appContainer') {
if (buildTool == 'docker' && configuration.artifactType == 'appContainer') {
script.commonPipelineEnvironment.setAppContainerProperty('artifactVersion', newVersion)
script.commonPipelineEnvironment.setAppContainerProperty('gitCommitId', gitCommitId)
} else {
@ -124,15 +111,11 @@ def call(Map parameters = [:]) {
script.commonPipelineEnvironment.setArtifactVersion(newVersion)
script.commonPipelineEnvironment.setGitCommitId(gitCommitId)
}
echo "[${stepName}]New version: ${newVersion}"
echo "[${STEP_NAME}]New version: ${newVersion}"
}
}
def getTimestamp(pattern){
return sh(returnStdout: true, script: "date +'${pattern}'").trim()
return sh(returnStdout: true, script: "date --universal +'${pattern}'").trim()
}

View File

@ -7,7 +7,7 @@ import com.sap.piper.MapUtils
import groovy.transform.Field
@Field def STEP_NAME = 'checksPublishResults'
@Field List TOOLS = [
@Field Set TOOLS = [
'aggregation', 'tasks', 'pmd', 'cpd', 'findbugs', 'checkstyle', 'eslint', 'pylint'
]
@ -23,15 +23,13 @@ def call(Map parameters = [:]) {
script = [commonPipelineEnvironment: commonPipelineEnvironment]
prepareDefaultValues script: script
prepare(parameters)
List configKeys = TOOLS.plus('archive')
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, STEP_NAME)
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, STEP_NAME)
Set configKeys = TOOLS.plus('archive')
Map configuration = ConfigurationMerger.merge(
script, STEP_NAME,
parameters, configKeys,
stepConfiguration, configKeys,
stepDefaults)
configKeys)
def doArchive = configuration.get('archive')
// JAVA

View File

@ -6,10 +6,10 @@ def call(Map parameters = [:], body) {
def PLUGIN_ID_DOCKER_WORKFLOW = 'docker-workflow'
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters){
def dockerImage = parameters.get('dockerImage', '')
Map dockerEnvVars = parameters.get('dockerEnvVars', [:])
def dockerOptions = parameters.get('dockerOptions', '')
Map dockerVolumeBind = parameters.get('dockerVolumeBind', [:])
def dockerImage = parameters.dockerImage ?: ''
Map dockerEnvVars = parameters.dockerEnvVars ?: [:]
def dockerOptions = parameters.dockerOptions ?: ''
Map dockerVolumeBind = parameters.dockerVolumeBind ?: [:]
if(dockerImage) {
@ -60,27 +60,34 @@ private getDockerOptions(Map dockerEnvVars, Map dockerVolumeBind, def dockerOpti
'HTTPS_PROXY',
'NO_PROXY'
]
def options = ""
def options = []
if (dockerEnvVars) {
for (String k : dockerEnvVars.keySet()) {
options += " --env ${k}=" + dockerEnvVars[k].toString()
options.add("--env ${k}=${dockerEnvVars[k].toString()}")
}
}
for (String envVar : specialEnvironments) {
if (dockerEnvVars == null || !dockerEnvVars.containsKey(envVar)) {
options += " --env ${envVar}"
options.add("--env ${envVar}")
}
}
if (dockerVolumeBind) {
for (String k : dockerVolumeBind.keySet()) {
options += " --volume ${k}:" + dockerVolumeBind[k].toString()
options.add("--volume ${k}:${dockerVolumeBind[k].toString()}")
}
}
if (dockerOptions) {
options += " ${dockerOptions}"
if (dockerOptions instanceof CharSequence) {
options.add(dockerOptions.toString())
} else if (dockerOptions instanceof List) {
for (String option : dockerOptions) {
options.add "${option}"
}
} else {
throw new IllegalArgumentException("Unexpected type for dockerOptions. Expected was either a list or a string. Actual type was: '${dockerOptions.getClass()}'")
}
return options
return options.join(' ')
}

View File

@ -14,10 +14,7 @@ def call(Map parameters = [:]) {
prepareDefaultValues script: script
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)
List parameterKeys = [
Set parameterKeys = [
'artifactVersion',
'influxServer',
'influxPrefix'
@ -25,12 +22,12 @@ def call(Map parameters = [:]) {
Map pipelineDataMap = [
artifactVersion: commonPipelineEnvironment.getArtifactVersion()
]
List stepConfigurationKeys = [
Set stepConfigurationKeys = [
'influxServer',
'influxPrefix'
]
Map configuration = ConfigurationMerger.mergeWithPipelineData(parameters, parameterKeys, pipelineDataMap, stepConfiguration, stepConfigurationKeys, stepDefaults)
Map configuration = ConfigurationMerger.merge(script, stepName, parameters, parameterKeys, pipelineDataMap, stepConfigurationKeys)
def artifactVersion = configuration.artifactVersion
if (!artifactVersion) {

View File

@ -7,12 +7,10 @@ def call(Map parameters = [:]) {
final script = parameters.script
prepareDefaultValues script: script
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, 'mavenExecute')
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, 'mavenExecute')
List parameterKeys = [
Set parameterKeys = [
'dockerImage',
'dockerOptions',
'globalSettingsFile',
'projectSettingsFile',
'pomPath',
@ -21,7 +19,7 @@ def call(Map parameters = [:]) {
'm2Path',
'defines'
]
List stepConfigurationKeys = [
Set stepConfigurationKeys = [
'dockerImage',
'globalSettingsFile',
'projectSettingsFile',
@ -29,7 +27,9 @@ def call(Map parameters = [:]) {
'm2Path'
]
Map configuration = ConfigurationMerger.merge(parameters, parameterKeys, stepConfiguration, stepConfigurationKeys, stepDefaults)
Map configuration = ConfigurationMerger.merge(script, 'mavenExecute',
parameters, parameterKeys,
stepConfigurationKeys)
String command = "mvn"
@ -75,7 +75,7 @@ def call(Map parameters = [:]) {
command += " ${defines}"
}
dockerExecute(dockerImage: configuration.dockerImage) { sh command }
dockerExecute(dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) { sh command }
}
}

View File

@ -1,21 +1,23 @@
import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger
import com.sap.piper.MtaUtils
import groovy.transform.Field
@Field def DEFAULT_MTA_JAR_NAME = 'mta.jar'
def call(Map parameters = [:]) {
def stepName = 'mtaBuild'
List parameterKeys = [
Set parameterKeys = [
'applicationName',
'buildTarget',
'mtaJarLocation'
]
List stepConfigurationKeys = [
'buildTarget'
]
List generalConfigurationKeys = [
Set stepConfigurationKeys = [
'applicationName',
'buildTarget',
'mtaJarLocation'
]
@ -25,16 +27,60 @@ def call(Map parameters = [:]) {
prepareDefaultValues script: script
final Map stepConfiguration = ConfigurationLoader.stepConfiguration(script, stepName)
final Map stepDefaults = ConfigurationLoader.defaultStepConfiguration(script, stepName)
final Map generalConfiguration = ConfigurationLoader.generalConfiguration(script)
final Map configuration = ConfigurationMerger.merge(
script, stepName,
parameters, parameterKeys,
generalConfiguration, generalConfigurationKeys, [:],
stepConfiguration, stepConfigurationKeys, stepDefaults)
stepConfigurationKeys)
MTA_JAR_FILE_VALIDATE: {
// same order like inside getMtaJar,
def mtaJarLocation = configuration?.mtaJarLocation ?: env?.MTA_JAR_LOCATION
def returnCodeLsMtaJar = sh script: "ls ${DEFAULT_MTA_JAR_NAME}", returnStatus:true
if(mtaJarLocation || ( !mtaJarLocation && returnCodeLsMtaJar != 0)) {
// toolValidate commented since it is does not work in
// conjunction with jenkins slaves.
// TODO: switch on again when the issue is resolved.
// toolValidate tool: 'mta', home: mtaJarLocation
echo 'toolValidate (mta) is disabled.'
} else {
echo "mta toolset (${DEFAULT_MTA_JAR_NAME}) has been found in current working directory. Using this version without further tool validation."
}
}
JAVA_HOME_CHECK : {
// in case JAVA_HOME is not set, but java is in the path we should not fail
// in order to be backward compatible. Before introducing that check here
// is worked also in case JAVA_HOME was not set, but java was in the path.
// toolValidate works only upon JAVA_HOME and fails in case it is not set.
def rc = sh script: 'which java' , returnStatus: true
if(script.JAVA_HOME || (!script.JAVA_HOME && rc != 0)) {
// toolValidate commented since it is does not work in
// conjunction with jenkins slaves.
// TODO: switch on again when the issue is resolved.
echo 'toolValidate (mta) is disabled.'
// toolValidate tool: 'java', home: script.JAVA_HOME
echo 'toolValidate (java) is disabled.'
} else {
echo 'Tool validation (java) skipped. JAVA_HOME not set, but java executable in path.'
}
}
def mtaYmlName = "${pwd()}/mta.yaml"
def applicationName = configuration.applicationName
if (!fileExists(mtaYmlName)) {
if (!applicationName) {
echo "'applicationName' not provided as parameter - will not try to generate mta.yml file"
} else {
MtaUtils mtaUtils = new MtaUtils(this)
mtaUtils.generateMtaDescriptorFromPackageJson("${pwd()}/package.json", mtaYmlName, applicationName)
}
}
def mtaYaml = readYaml file: "${pwd()}/mta.yaml"
//[Q]: Why not yaml.dump()? [A]: This reformats the whole file.
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${pwd()}/mta.yaml\""
@ -61,21 +107,20 @@ def call(Map parameters = [:]) {
}
private getMtaJar(stepName, configuration) {
def mtaJarLocation = 'mta.jar' //default, maybe it is in current working directory
def mtaJarLocation = DEFAULT_MTA_JAR_NAME //default, maybe it is in current working directory
if(configuration?.mtaJarLocation){
mtaJarLocation = "${configuration.mtaJarLocation}/mta.jar"
mtaJarLocation = "${configuration.mtaJarLocation}/${DEFAULT_MTA_JAR_NAME}"
echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from configuration."
return mtaJarLocation
}
if(env?.MTA_JAR_LOCATION){
mtaJarLocation = "${env.MTA_JAR_LOCATION}/mta.jar"
mtaJarLocation = "${env.MTA_JAR_LOCATION}/${DEFAULT_MTA_JAR_NAME}"
echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from environment."
return mtaJarLocation
}
echo "[$stepName] Using MTA JAR from current working directory."
return mtaJarLocation
}
}

View File

@ -1,13 +1,26 @@
import com.sap.piper.Utils
import groovy.transform.Field
import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger
import com.sap.piper.ConfigurationType
@Field def NEO_DEFAULT_CMD = 'neo.sh'
//
// envProps may be overwritten by tests, but only by tests.
// [Q] Why not simply using the Map returned by getenv() itself?
// [A] The unmodifiable map returned by getenv() is not serializable
// Since everythings needs to be serializabe (CPS pattern) we
// cannot use that map directly.
@Field Map envProps = System.getenv().findAll { true }
def call(parameters = [:]) {
def stepName = 'neoDeploy'
List parameterKeys = [
Set parameterKeys = [
'applicationName',
'archivePath',
'account',
@ -27,7 +40,7 @@ def call(parameters = [:]) {
'warAction'
]
List stepConfigurationKeys = [
Set stepConfigurationKeys = [
'account',
'dockerEnvVars',
'dockerImage',
@ -98,7 +111,7 @@ def call(parameters = [:]) {
def deployHost
def deployAccount
def credentialsId = configuration.get('neoCredentialsId', '')
def credentialsId = configuration.get('neoCredentialsId')
def deployMode = configuration.deployMode
def warAction
def propertiesFile
@ -186,6 +199,51 @@ def call(parameters = [:]) {
dockerEnvVars: configuration.get('dockerEnvVars'),
dockerOptions: configuration.get('dockerOptions')) {
NEO_HOME_CHECK: {
// same order like inside getNeoExecutable
String neoHome = configuration.neoHome ?: env?.NEO_HOME
// In case neo home is not set, but neo toolset is simply
// in the path, we trust that everything is OK. In order to
// validate the version also in this case, we need to adjust
// toolValidate.
def rc = sh script: "which ${NEO_DEFAULT_CMD}", returnStatus: true
if(neoHome || (!neoHome && rc != 0)) {
// toolValidate commented since it is does not work in
// conjunction with jenkins slaves.
// TODO: switch on again when the issue is resolved.
// toolValidate tool: 'neo', home: neoHome
echo 'toolValidate (neo) is disabled.'
} else {
echo "neo (${NEO_DEFAULT_CMD}) has been found in path. Using this neo version without futher tool validation."
}
}
JAVA_HOME_CHECK : {
//
// [Q] How is the java executable resolved by neo?
// [A] They check for JAVA_HOME. If not present, they
// try to resolve it via ```which java```.
//
def javaHome = envProps.JAVA_HOME
def rc = sh script: 'which java', returnStatus: true
if(!javaHome && rc == 0) {
// java home is not set`, but java is in path.
// --> we skip the check and trust that we can work
// with java from the path.
echo "Skipping tool validate check (java). " +
"Java executable in path, but no JAVA_HOME found."
} else {
// toolValidate commented since it is does not work in
// conjunction with jenkins slaves.
// TODO: switch on again when the issue is resolved.
//toolValidate tool: 'java', home: javaHome
echo 'toolValidate (java) is disabled.'
}
}
sh """${neoDeployScript} \
${commonDeployParams}
"""
@ -196,16 +254,16 @@ def call(parameters = [:]) {
private getNeoExecutable(configuration) {
def neoExecutable = 'neo.sh' // default, if nothing below applies maybe it is the path.
def neoExecutable = NEO_DEFAULT_CMD // default, if nothing below applies maybe it is the path.
if (configuration.neoHome) {
neoExecutable = "${configuration.neoHome}/tools/neo.sh"
neoExecutable = "${configuration.neoHome}/tools/${NEO_DEFAULT_CMD}"
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from configuration."
return neoExecutable
}
if (env?.NEO_HOME) {
neoExecutable = "${env.NEO_HOME}/tools/neo.sh"
neoExecutable = "${env.NEO_HOME}/tools/${NEO_DEFAULT_CMD}"
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from environment."
return neoExecutable
}