mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-04 04:07:16 +02:00
Add groovy file and documentation for cloneGitRepo step (#1954)
* Add groovy file and documentation * Add quotes to docu * Fix request
This commit is contained in:
parent
46284d8f34
commit
13e5a943b2
@ -117,7 +117,7 @@ func triggerClone(repositoryName string, branchName string, cloneConnectionDetai
|
||||
if repositoryName == "" {
|
||||
return uriConnectionDetails, errors.New("An empty string was passed for the parameter 'repositoryName'")
|
||||
}
|
||||
jsonBody := []byte(`{"sc_name":"` + repositoryName + `"}`)
|
||||
jsonBody := []byte(`{"sc_name":"` + repositoryName + `", "branch_name":"` + branchName + `"}`)
|
||||
resp, err = abaputils.GetHTTPResponse("POST", cloneConnectionDetails, jsonBody, client)
|
||||
if err != nil {
|
||||
err = abaputils.HandleHTTPError(resp, err, "Could not clone the Repository / Software Component "+repositoryName+" with branch "+branchName, uriConnectionDetails)
|
||||
|
92
documentation/docs/steps/abapEnvironmentCloneGitRepo.md
Normal file
92
documentation/docs/steps/abapEnvironmentCloneGitRepo.md
Normal file
@ -0,0 +1,92 @@
|
||||
# ${docGenStepName}
|
||||
|
||||
## ${docGenDescription}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
A SAP Cloud Platform ABAP Environment system is available.
|
||||
On this system, a [Communication User](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/0377adea0401467f939827242c1f4014.html), a [Communication System](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/1bfe32ae08074b7186e375ab425fb114.html) and a [Communication Arrangement](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/a0771f6765f54e1c8193ad8582a32edb.html) is setup for the Communication Scenario "SAP Cloud Platform ABAP Environment - Software Component Test Integration (SAP_COM_0510)". This can be done manually through the respective applications on the SAP Cloud Platform ABAP Environment System or through creating a service key for the system on cloud foundry with the parameters {"scenario_id": "SAP_COM_0510", "type": "basic"}. In a pipeline, you can do this with the step [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/). In addition, the software component should be cloned into the system instance. You can do this with the step [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/).
|
||||
|
||||
## ${docGenParameters}
|
||||
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## ${docJenkinsPluginDependencies}
|
||||
|
||||
## Example: Configuration in the config.yml
|
||||
|
||||
The recommended way to configure your pipeline is via the config.yml file. In this case, calling the step in the Jenkinsfile is reduced to one line:
|
||||
|
||||
```groovy
|
||||
abapEnvironmentCheckoutBranch script: this
|
||||
```
|
||||
|
||||
If you want to provide the host and credentials of the Communication Arrangement directly, the configuration could look as follows:
|
||||
|
||||
```yaml
|
||||
|
||||
steps:
|
||||
abapEnvironmentCloneGitRepo:
|
||||
repositoryName: '/DMO/GIT_REPOSITORY'
|
||||
branchName: 'my-demo-branch'
|
||||
abapCredentialsId: 'abapCredentialsId'
|
||||
host: '1234-abcd-5678-efgh-ijk.abap.eu10.hana.ondemand.com'
|
||||
```
|
||||
Please note that the branchName parameter specifies the target branch you want to clone. Also keep in mind that the repositoryName parameter must define a single repository.
|
||||
|
||||
Another option is to read the host and credentials from the cloud foundry service key of the respective instance. Furthermore, if you want to clone multiple repositories, they can be specified in a configuration file.
|
||||
|
||||
With this approach the `config.yml` would look like this:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
abapEnvironmentCloneGitRepo:
|
||||
repositories: 'repositories.yml'
|
||||
cfCredentialsId: 'cfCredentialsId'
|
||||
cfApiEndpoint: 'https://test.server.com'
|
||||
cfOrg: 'cfOrg'
|
||||
cfSpace: 'cfSpace'
|
||||
cfServiceInstance: 'cfServiceInstance'
|
||||
cfServiceKeyName: 'cfServiceKeyName'
|
||||
```
|
||||
|
||||
and the configuration file `repositories.yml` would look like this:
|
||||
|
||||
```yaml
|
||||
repositories:
|
||||
- name: '/DMO/GIT_REPOSITORY'
|
||||
branch: 'master'
|
||||
- name: '/DMO/SOFTWARE_COMPONENT'
|
||||
branch: 'feature'
|
||||
```
|
||||
|
||||
## Example: Configuration in the Jenkinsfile
|
||||
|
||||
It is also possible to call the steps - including all parameters - directly in the Jenkinsfile.
|
||||
In the first example, the host and the credentialsId of the Communication Arrangement are directly provided.
|
||||
|
||||
```groovy
|
||||
abapEnvironmentCloneGitRepo (
|
||||
script: this,
|
||||
repositoryName: '/DMO/GIT_REPOSITORY',
|
||||
branchName: 'my-demo-branch',
|
||||
abapCredentialsId: 'abapCredentialsId',
|
||||
host: '1234-abcd-5678-efgh-ijk.abap.eu10.hana.ondemand.com'
|
||||
)
|
||||
```
|
||||
|
||||
In the second example, the host and credentialsId will be read from the provided cloud foundry service key of the specified service instance.
|
||||
|
||||
```groovy
|
||||
abapEnvironmentCloneGitRepo (
|
||||
script: this,
|
||||
repositoryName: '/DMO/GIT_REPOSITORY',
|
||||
branchName: 'my-demo-branch'
|
||||
abapCredentialsId: 'cfCredentialsId',
|
||||
cfApiEndpoint: 'https://test.server.com',
|
||||
cfOrg: 'cfOrg',
|
||||
cfSpace: 'cfSpace',
|
||||
cfServiceInstance: 'cfServiceInstance',
|
||||
cfServiceKeyName: 'cfServiceKeyName'
|
||||
)
|
||||
```
|
@ -40,6 +40,7 @@ nav:
|
||||
- Extensibility: extensibility.md
|
||||
- 'Library steps':
|
||||
- abapEnvironmentCheckoutBranch: steps/abapEnvironmentCheckoutBranch.md
|
||||
- abapEnvironmentCloneGitRepo: steps/abapEnvironmentCloneGitRepo.md
|
||||
- abapEnvironmentPullGitRepo: steps/abapEnvironmentPullGitRepo.md
|
||||
- abapEnvironmentRunATCCheck: steps/abapEnvironmentRunATCCheck.md
|
||||
- artifactPrepareVersion: steps/artifactPrepareVersion.md
|
||||
|
@ -106,8 +106,15 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
}
|
||||
|
||||
private static fieldRelatedWhitelist = [
|
||||
'abapEnvironmentCheckoutBranch', //implementing new golang pattern without fields
|
||||
'abapEnvironmentCloneGitRepo', //implementing new golang pattern without fields
|
||||
'abapEnvironmentPullGitRepo', //implementing new golang pattern without fields
|
||||
'abapEnvironmentPipeline', // special step (infrasturcture)
|
||||
'abapEnvironmentRunATCCheck', //implementing new golang pattern without fields
|
||||
'artifactPrepareVersion',
|
||||
'cloudFoundryCreateService', //implementing new golang pattern without fields
|
||||
'cloudFoundryCreateServiceKey', //implementing new golang pattern without fields
|
||||
'cloudFoundryDeleteService', //implementing new golang pattern without fields
|
||||
'durationMeasure', // only expects parameters via signature
|
||||
'prepareDefaultValues', // special step (infrastructure)
|
||||
'piperPipeline', // special step (infrastructure)
|
||||
@ -120,15 +127,12 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
'piperStageWrapper', //intended to be called from within stages
|
||||
'buildSetResult',
|
||||
'runClosures',
|
||||
'abapEnvironmentPullGitRepo', //implementing new golang pattern without fields
|
||||
'checkmarxExecuteScan', //implementing new golang pattern without fields
|
||||
'githubPublishRelease', //implementing new golang pattern without fields
|
||||
'kubernetesDeploy', //implementing new golang pattern without fields
|
||||
'piperExecuteBin', //implementing new golang pattern without fields
|
||||
'protecodeExecuteScan', //implementing new golang pattern without fields
|
||||
'xsDeploy', //implementing new golang pattern without fields
|
||||
'cloudFoundryDeleteService', //implementing new golang pattern without fields
|
||||
'cloudFoundryCreateServiceKey', //implementing new golang pattern without fields
|
||||
'npmExecuteScripts', //implementing new golang pattern without fields
|
||||
'npmExecuteLint', //implementing new golang pattern without fields
|
||||
'malwareExecuteScan', //implementing new golang pattern without fields
|
||||
@ -139,7 +143,6 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
'mtaBuild', //implementing new golang pattern without fields
|
||||
'nexusUpload', //implementing new golang pattern without fields
|
||||
'piperPipelineStageArtifactDeployment', //stage without step flags
|
||||
'abapEnvironmentRunATCCheck', //implementing new golang pattern without fields
|
||||
'sonarExecuteScan', //implementing new golang pattern without fields
|
||||
'gctsCreateRepository', //implementing new golang pattern without fields
|
||||
'gctsRollback', //implementing new golang pattern without fields
|
||||
@ -148,10 +151,8 @@ public class CommonStepsTest extends BasePiperTest{
|
||||
'fortifyExecuteScan', //implementing new golang pattern without fields
|
||||
'gctsDeploy', //implementing new golang pattern without fields
|
||||
'containerSaveImage', //implementing new golang pattern without fields
|
||||
'cloudFoundryCreateService',
|
||||
'detectExecuteScan', //implementing new golang pattern without fields
|
||||
'kanikoExecute', //implementing new golang pattern without fields
|
||||
'abapEnvironmentCheckoutBranch' //implementing new golang pattern without fields
|
||||
'kanikoExecute' //implementing new golang pattern without fields
|
||||
]
|
||||
|
||||
@Test
|
||||
|
11
vars/abapEnvironmentCloneGitRepo.groovy
Normal file
11
vars/abapEnvironmentCloneGitRepo.groovy
Normal file
@ -0,0 +1,11 @@
|
||||
import groovy.transform.Field
|
||||
|
||||
@Field String STEP_NAME = getClass().getName()
|
||||
@Field String METADATA_FILE = 'metadata/abapEnvironmentCloneGitRepo.yaml'
|
||||
|
||||
void call(Map parameters = [:]) {
|
||||
List credentials = [
|
||||
[type: 'usernamePassword', id: 'abapCredentialsId', env: ['PIPER_username', 'PIPER_password']]
|
||||
]
|
||||
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials, false, false, true)
|
||||
}
|
Loading…
Reference in New Issue
Block a user