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

Fiori Scenario from Neo to CF (#2164)

* Fiori Scenario from Neo to CF

* Fiori Scenario from Neo to CF - Review
- error on unknown deploy target
- codeclimate
- remove obsolete sample files

* Minor language changes
This commit is contained in:
Roland Stengel 2020-10-15 13:29:52 +02:00 committed by GitHub
parent 64596a556d
commit 1488c4d355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 136 additions and 69 deletions

View File

@ -1,15 +1,11 @@
# Build and Deploy SAPUI5 or SAP Fiori Applications on SAP Cloud Platform with Jenkins
Build an application based on SAPUI5 or SAP Fiori with Jenkins and deploy the build result into an SAP Cloud Platform account in the Neo environment.
Build an application based on SAPUI5 or SAP Fiori with Jenkins and deploy the build result into an SAP Cloud Platform account in the Cloud Foundry environment. Optionally, deploy the build result into the Neo environment.
## Prerequisites
* You have installed the Java Runtime Environment 8.
* You have installed Jenkins 2.60.3 or higher.
* You have set up Project “Piper”. See [README](https://github.com/SAP/jenkins-library/blob/master/README.md).
* You have installed the Multi-Target Application (MTA) Archive Builder 1.0.6 or newer. See [SAP Development Tools](https://tools.hana.ondemand.com/#cloud).
* You have installed Node.js including node and npm. See [Node.js](https://nodejs.org/en/download/).
* You have installed the SAP Cloud Platform Neo Environment SDK. See [SAP Development Tools](https://tools.hana.ondemand.com/#cloud).
* You have an account on SAP Cloud Platform in the Cloud Foundry environment. See [Accounts](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/8ed4a705efa0431b910056c0acdbf377.html).
* You have set up Project “Piper”. See [Guided Tour](https://sap.github.io/jenkins-library/guidedtour/).
### Project Prerequisites
@ -19,16 +15,13 @@ On the project level, provide and adjust the following template:
| File Name | Description | Position |
|-----|-----|-----|
| [`.npmrc`](https://github.com/SAP/jenkins-library/blob/master/documentation/docs/scenarios/ui5-sap-cp/files/.npmrc) | This file contains a reference to the SAP NPM registry (`@sap:registry https://npm.sap.com`), which is required to fetch the dependencies required to build the application. | Place the `.npmrc` file in the root directory of your project. |
| [`mta.yaml`](https://github.com/SAP/jenkins-library/blob/master/documentation/docs/scenarios/ui5-sap-cp/files/mta.yaml) | This file controls the behavior of the MTA toolset. | Place the `mta.yaml` file in your application root folder and adjust the values in brackets with your data. |
| [`package.json`](https://github.com/SAP/jenkins-library/blob/master/documentation/docs/scenarios/ui5-sap-cp/files/package.json) | This file lists the required development dependencies for the build. | Add the content of the `package.json` file to your existing `package.json` file. |
| [`Gruntfile.js`](https://github.com/SAP/jenkins-library/blob/master/documentation/docs/scenarios/ui5-sap-cp/files/Gruntfile.js) | This file controls the grunt build. By default the tasks `clean`, `build`, and `lint` are executed. | Place the `Gruntfile.js` in the root directory of your project. |
| [`mta.yaml`](https://github.com/SAP/jenkins-library/blob/master/documentation/docs/scenarios/ui5-sap-cp/files/mta.yaml) | This file controls the behavior of the [MTA toolset](https://sap.github.io/cloud-mta-build-tool/). | Place the `mta.yaml` file in your application root folder and replace the values in brackets with your data. |
## Context
This scenario combines various different steps to create a complete pipeline.
In this scenario, we want to show how to build an application based on SAPUI5 or SAP Fiori by using the multi-target application (MTA) concept and how to deploy the build result into an SAP Cloud Platform account in the Neo environment. This document comprises the [mtaBuild](../../../steps/mtaBuild/) and the [neoDeploy](../../../steps/neoDeploy/) steps.
In this scenario, we want to show how to build an application based on SAPUI5 or SAP Fiori by using the multi-target application (MTA) concept, and how to deploy the build result into an SAP Cloud Platform account in the Cloud Foundry environment. This document comprises the [mtaBuild](../../../steps/mtaBuild/) and the [cloudFoundryDeploy](../../../steps/cloudFoundryDeploy/) steps.
![This pipeline in Jenkins Blue Ocean](images/pipeline.jpg)
###### Screenshot: Build and Deploy Process in Jenkins
@ -45,42 +38,44 @@ Following the convention for pipeline definitions, use a `Jenkinsfile` which res
fioriOnCloudPlatformPipeline script:this
```
`fioriOnCloudPlatform` is a so called _scenario step_ that wraps the [mtaBuild](https://sap.github.io/jenkins-library/steps/mtaBuild/) and the [neoDeploy](https://sap.github.io/jenkins-library/steps/neoDeploy/) steps.
[fioriOnCloudPlatformPipeline](https://sap.github.io/jenkins-library/steps/fioriOnCloudPlatformPipeline) is a so called _scenario step_ that wraps mainly the [MTA Build](https://sap.github.io/jenkins-library/steps/mtaBuild/) step and the [SAP Cloud Platform Deployment](https://sap.github.io/jenkins-library/steps/cloudFoundryDeploy/) step.
### Configuration (`.pipeline/config.yml`)
### Scenario Configuration
This is a basic configuration example, which is also located in the sources of the project. The configuration corresponds to the steps wrapped in `fioriOnCloudPlatformPipeline`.
This is a basic configuration example, which also resides in the sources of the project. Edit `.pipeline/config.yml` below the root directory. The configuration corresponds to the steps wrapped in `fioriOnCloudPlatformPipeline`. For more information, see [mtaBuild](https://sap.github.io/jenkins-library/steps/mtaBuild/) and [cloudFoundryDeploy](https://sap.github.io/jenkins-library/steps/cloudFoundryDeploy/).
```yaml
steps:
mtaBuild:
buildTarget: 'NEO'
platform: 'neo'
platform: 'CF'
cloudFoundryDeploy:
cloudFoundry:
apiEndpoint: 'your-cf-endpoint' # default: 'https://api.cf.eu10.hana.ondemand.com'
org: 'your-org-id'
space: 'your-space-id'
credentialsId: 'CF-jenkins-credentials-id'
```
### Optional environment
Optionally, you can use [fioriOnCloudPlatformPipeline](https://sap.github.io/jenkins-library/steps/fioriOnCloudPlatformPipeline) to deploy your build result into the Neo environment. For more information, see [neoDeploy](https://sap.github.io/jenkins-library/steps/neoDeploy/).
```yaml
steps:
mtaBuild:
platform: 'NEO'
neoDeploy:
neo:
credentialsId: 'NEO_DEPLOY'
credentialsId: 'NEO-jenkins-credentials-id'
account: 'your-account-id'
host: 'hana.ondemand.com'
```
#### Configuration for the MTA Build
| Parameter | Description |
| -----------------|----------------|
| `buildTarget` | The target platform to which the mtar can be deployed. Possible values are: `CF`, `NEO`, `XSA` |
| `mtaJarLocation` | The location of the multi-target application archive builder jar file, including file name and extension. |
#### Configuration for the Deployment to SAP Cloud Platform
| Parameter | Description |
| -------------------|-------------|
| `account` | The SAP Cloud Platform account to deploy to. |
| `credentialsId` | The Jenkins credentials that contain the user and password which are used for the deployment on SAP Cloud Platform.|
| `host` | The SAP Cloud Platform host to deploy to. |
### Parameters
For the detailed description of the relevant parameters, see:
* [fioriOnCloudPlatformPipeline](../../../steps/fioriOnCloudPlatformPipeline/)
* [mtaBuild](../../../steps/mtaBuild/)
* [cloudFoundryDeploy](../../../steps/cloudFoundryDeploy/)
* [neoDeploy](../../../steps/neoDeploy/)

View File

@ -1,10 +0,0 @@
module.exports = function (grunt) {
'use strict';
grunt.loadNpmTasks('@sap/grunt-sapui5-bestpractice-build');
grunt.registerTask('default', [
'lint',
'clean',
'build'
]);
};

View File

@ -2,16 +2,7 @@ _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:
name: "<Name of your Fiori application>"
version: <version number of your application>-${timestamp}
build-parameters:
builder: grunt
build-result: dist

View File

@ -1,10 +0,0 @@
{
"name": "<name of the package>",
"version": "<version of the package>",
"description": "<description of the package>",
"private": true,
"devDependencies": {
"grunt": "1.0.1",
"@sap/grunt-sapui5-bestpractice-build": "1.3.17"
}
}

View File

@ -17,6 +17,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import com.sap.piper.JenkinsUtils
@ -52,7 +53,8 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
Gruntfile.js and configure default tasks (e.g. lint, clean, build)
* mta.yaml
*/
private ExpectedException thrown = new ExpectedException().none()
JenkinsStepRule stepRule = new JenkinsStepRule(this)
JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
@ -63,6 +65,7 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(readYamlRule)
.around(thrown)
.around(stepRule)
.around(shellRule)
.around(jlr)
@ -71,6 +74,14 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
.around(new JenkinsCredentialsRule(this)
.withCredentials('CI_CREDENTIALS_ID', 'foo', 'terceSpot'))
private writeInfluxMap = [:]
class JenkinsUtilsMock extends JenkinsUtils {
def isJobStartedByUser() {
return true
}
}
@Before
void setup() {
//
@ -98,20 +109,31 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
})
Utils.metaClass.echo = { def m -> }
helper.registerAllowedMethod('influxWriteData', [Map.class], { m ->
writeInfluxMap = m
})
UUID.metaClass.static.randomUUID = { -> 1 }
}
@After
public void tearDown() {
Utils.metaClass = null
UUID.metaClass = null
}
@Test
void straightForwardTest() {
void straightForwardTestNeo() {
nullScript
.commonPipelineEnvironment
.configuration = [steps:
[neoDeploy:
[mtaBuild:
[
platform: 'NEO'
],
neoDeploy:
[neo:
[ host: 'hana.example.com',
account: 'myTestAccount',
@ -120,9 +142,7 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
]
]
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript,
platform: 'NEO',
)
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
//
// the deployable is exchanged between the involved steps via this property:
@ -142,4 +162,75 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
.hasSingleQuotedOption('source', 'test.mtar')
.hasArgument('synchronous'))
}
@Test
void straightForwardTestCF() {
nullScript
.commonPipelineEnvironment
.configuration = [steps:
[mtaBuild:
[
platform: 'CF'
],
cloudFoundryDeploy:
[ deployTool: 'mtaDeployPlugin',
cloudFoundry:
[ apiEndpoint: 'https://api.cf.hana.example.com',
org: 'testOrg',
space: 'testSpace',
credentialsId: 'CI_CREDENTIALS_ID'
]
]
]
]
stepRule.step.fioriOnCloudPlatformPipeline(
script: nullScript,
jenkinsUtilsStub: new JenkinsUtilsMock()
)
assertThat(shellRule.shell, hasItem(containsString('cf login -u "foo" -p \'terceSpot\' -a https://api.cf.hana.example.com -o "testOrg" -s "testSpace"')))
}
@Test
void errorNoTargetDefined() {
nullScript
.commonPipelineEnvironment
.configuration = [steps:
[neoDeploy:
[neo:
[ host: 'hana.example.com',
account: 'myTestAccount',
]
]
]
]
thrown.expect(Exception)
thrown.expectMessage('Deployment failed: no valid deployment target defined')
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
}
@Test
void errorUnknownTargetDefined() {
nullScript
.commonPipelineEnvironment
.configuration = [steps:
[mtaBuild:
[
platform: 'UNKNOWN'
]
]
]
thrown.expect(Exception)
thrown.expectMessage('Deployment failed: no valid deployment target defined')
stepRule.step.fioriOnCloudPlatformPipeline(script: nullScript)
}
}

View File

@ -43,7 +43,17 @@ void call(parameters = [:]) {
stage('deploy') {
neoDeploy(parameters)
def mtaBuildCfg = parameters.script.commonPipelineEnvironment.getStepConfiguration('mtaBuild', '')
if((mtaBuildCfg.platform == 'NEO') || (mtaBuildCfg.buildTarget == 'NEO')) {
neoDeploy(parameters)
}
else if((mtaBuildCfg.platform == 'CF') || (mtaBuildCfg.buildTarget == 'CF')) {
cloudFoundryDeploy(parameters)
}
else {
error "Deployment failed: no valid deployment target defined! Find details in https://sap.github.io/jenkins-library/steps/mtaBuild/#platform"
}
}
// Cut and paste lines above in order to create a pipeline from this scenario