mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Merge branch 'master' into pr/configLoaderWithoutScriptReference
This commit is contained in:
commit
8e3cc5e0f6
4
.pipeline/config.yml
Normal file
4
.pipeline/config.yml
Normal file
@ -0,0 +1,4 @@
|
||||
steps:
|
||||
githubPublishRelease:
|
||||
owner: SAP
|
||||
repository: jenkins-library
|
17
.travis.yml
17
.travis.yml
@ -22,13 +22,26 @@ cache:
|
||||
jobs:
|
||||
include:
|
||||
- stage: Tests
|
||||
name: Unit Tests
|
||||
name: Golang Build
|
||||
if: type = pull_request
|
||||
script:
|
||||
- docker build -t piper:${TRAVIS_BRANCH} .
|
||||
- name: Golang Build & Publish
|
||||
if: type != pull_request && repo = "SAP/jenkins-library" && branch = "master"
|
||||
script:
|
||||
- docker build -t piper:${TRAVIS_BRANCH} .
|
||||
- docker create --name piper_${TRAVIS_BRANCH} piper:${TRAVIS_BRANCH}
|
||||
- docker cp piper_${TRAVIS_BRANCH}:/build/piper .
|
||||
- docker rm piper_${TRAVIS_BRANCH}
|
||||
- cp ./piper ./piper_master
|
||||
- chmod +x ./piper
|
||||
- ./piper githubPublishRelease --token ${GITHUB_TOKEN} --version latest --updateAsset --assetPath ./piper_master
|
||||
- name: Groovy Unit Tests
|
||||
before_script:
|
||||
- curl -L --output cc-test-reporter https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64
|
||||
- chmod +x ./cc-test-reporter
|
||||
- ./cc-test-reporter before-build
|
||||
script:
|
||||
- docker build -t piper:latest .
|
||||
- mvn package --batch-mode
|
||||
after_script:
|
||||
- JACOCO_SOURCE_PATH="src vars test" ./cc-test-reporter format-coverage target/site/jacoco/jacoco.xml --input-type jacoco
|
||||
|
@ -7,7 +7,6 @@ RUN go test ./... -cover
|
||||
|
||||
## ONLY tests so far, building to be added later
|
||||
# execute build
|
||||
# RUN go build -o piper
|
||||
RUN export GIT_COMMIT=$(git rev-parse HEAD) && \
|
||||
export GIT_REPOSITORY=$(git config --get remote.origin.url) && \
|
||||
go build \
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
* 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)".
|
||||
* It is recommended to use the Jenkins credentials configuration for user and password handling and wrap the call to "abapEnvironmentPullGitRepo" with the Jenkins Step "withCredentials".
|
||||
|
||||
## ${docGenParameters}
|
||||
|
||||
@ -17,13 +16,10 @@
|
||||
## Example
|
||||
|
||||
```groovy
|
||||
withCredentials([usernamePassword(credentialsId: 'myCredentialsId', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
|
||||
abapEnvironmentPullGitRepo(
|
||||
host : ' 1234-abcd-5678-efgh-ijk.abap.eu10.hana.ondemand.com',
|
||||
repositoryName : '/DMO/GIT_REPOSITORY',
|
||||
username : "\$USER",
|
||||
password : "\$PASSWORD",
|
||||
script : this
|
||||
)
|
||||
}
|
||||
abapEnvironmentPullGitRepo (
|
||||
host : '1234-abcd-5678-efgh-ijk.abap.eu10.hana.ondemand.com',
|
||||
repositoryName : '/DMO/GIT_REPOSITORY',
|
||||
credentialsId : "myCredentialsId",
|
||||
script : this
|
||||
)
|
||||
```
|
||||
|
@ -27,6 +27,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
|
||||
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
|
||||
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
|
||||
private JenkinsCredentialsRule credentialsRule = new JenkinsCredentialsRule(this).withCredentials('test_credentialsId', 'user', 'password')
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules.getCommonRules(this)
|
||||
@ -34,6 +35,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
.around(thrown)
|
||||
.around(stepRule)
|
||||
.around(loggingRule)
|
||||
.around(credentialsRule)
|
||||
.around(shellRule)
|
||||
|
||||
@Before
|
||||
@ -57,7 +59,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
loggingRule.expect("[abapEnvironmentPullGitRepo] Entity URI: https://example.com/URI")
|
||||
loggingRule.expect("[abapEnvironmentPullGitRepo] Pull Status: SUCCESS")
|
||||
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
||||
|
||||
assertThat(shellRule.shell[0], containsString(/#!\/bin\/bash curl -I -X GET https:\/\/example.com\/sap\/opu\/odata\/sap\/MANAGE_GIT_REPOSITORY\/Pull -H 'Authorization: Basic dXNlcjpwYXNzd29yZA==' -H 'Accept: application\/json' -H 'x-csrf-token: fetch' -D headerFileAuth-1.txt/))
|
||||
assertThat(shellRule.shell[1], containsString(/#!\/bin\/bash curl -X POST "https:\/\/example.com\/sap\/opu\/odata\/sap\/MANAGE_GIT_REPOSITORY\/Pull" -H 'Authorization: Basic dXNlcjpwYXNzd29yZA==' -H 'Accept: application\/json' -H 'Content-Type: application\/json' -H 'x-csrf-token: TOKEN' --cookie headerFileAuth-1.txt -D headerFilePost-1.txt -d '{ "sc_name": "Z_DEMO_DM" }'/))
|
||||
@ -83,7 +85,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[abapEnvironmentPullGitRepo] Pull Failed")
|
||||
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
||||
|
||||
}
|
||||
|
||||
@ -104,7 +106,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[abapEnvironmentPullGitRepo] Pull Failed")
|
||||
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
||||
|
||||
}
|
||||
|
||||
@ -122,7 +124,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[abapEnvironmentPullGitRepo] Error: text")
|
||||
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
||||
|
||||
}
|
||||
|
||||
@ -139,7 +141,7 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage("[abapEnvironmentPullGitRepo] Error: 401 Unauthorized")
|
||||
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', repositoryName: 'Z_DEMO_DM', credentialsId: 'test_credentialsId')
|
||||
|
||||
}
|
||||
|
||||
@ -147,14 +149,14 @@ public class AbapEnvironmentPullGitRepoTest extends BasePiperTest {
|
||||
public void checkRepositoryProvided() {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("Repository / Software Component not provided")
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, host: 'example.com', credentialsId: 'test_credentialsId')
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkHostProvided() {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage("Host not provided")
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, repositoryName: 'REPO', username: 'user', password: 'password')
|
||||
stepRule.step.abapEnvironmentPullGitRepo(script: nullScript, repositoryName: 'REPO', credentialsId: 'test_credentialsId')
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -130,7 +130,7 @@ class SonarExecuteScanTest extends BasePiperTest {
|
||||
binding.setVariable('env', [
|
||||
'CHANGE_ID': '42',
|
||||
'CHANGE_TARGET': 'master',
|
||||
'BRANCH_NAME': 'feature/anything'
|
||||
'CHANGE_BRANCH': 'feature/anything'
|
||||
])
|
||||
nullScript.commonPipelineEnvironment.setGithubOrg('testOrg')
|
||||
//nullScript.commonPipelineEnvironment.setGithubRepo('testRepo')
|
||||
|
@ -22,13 +22,9 @@ import java.util.UUID
|
||||
]
|
||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
|
||||
/**
|
||||
* Specifies the communication user of the communication scenario SAP_COM_0510
|
||||
* Jenkins CredentialsId containing the communication user and password of the communciation scenario SAP_COM_0510
|
||||
*/
|
||||
'username',
|
||||
/**
|
||||
* Specifies the password of the communication user
|
||||
*/
|
||||
'password'
|
||||
'credentialsId'
|
||||
])
|
||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
||||
/**
|
||||
@ -58,12 +54,15 @@ void call(Map parameters = [:]) {
|
||||
.collectValidationFailures()
|
||||
.withMandatoryProperty('host', 'Host not provided')
|
||||
.withMandatoryProperty('repositoryName', 'Repository / Software Component not provided')
|
||||
.withMandatoryProperty('username')
|
||||
.withMandatoryProperty('password')
|
||||
.withMandatoryProperty('credentialsId')
|
||||
.use()
|
||||
|
||||
String usernameColonPassword = configuration.username + ":" + configuration.password
|
||||
String authToken = usernameColonPassword.bytes.encodeBase64().toString()
|
||||
String authToken
|
||||
withCredentials([usernamePassword(credentialsId: configuration.credentialsId, usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
|
||||
String userColonPassword = "${USER}:${PASSWORD}"
|
||||
authToken = userColonPassword.bytes.encodeBase64().toString()
|
||||
}
|
||||
|
||||
String urlString = 'https://' + configuration.host + '/sap/opu/odata/sap/MANAGE_GIT_REPOSITORY/Pull'
|
||||
echo "[${STEP_NAME}] General Parameters: URL = \"${urlString}\", repositoryName = \"${configuration.repositoryName}\""
|
||||
HeaderFiles headerFiles = new HeaderFiles()
|
||||
@ -133,7 +132,6 @@ private String triggerPull(Map configuration, String url, String authToken, Head
|
||||
|
||||
private String pollPullStatus(String url, String authToken, HeaderFiles headerFiles) {
|
||||
|
||||
String headerFile = "headerPoll.txt"
|
||||
String status = "R";
|
||||
while(status == "R") {
|
||||
|
||||
|
@ -173,7 +173,7 @@ void call(Map parameters = [:]) {
|
||||
// see https://sonarcloud.io/documentation/analysis/pull-request/
|
||||
config.options.add("sonar.pullrequest.key=${env.CHANGE_ID}")
|
||||
config.options.add("sonar.pullrequest.base=${env.CHANGE_TARGET}")
|
||||
config.options.add("sonar.pullrequest.branch=${env.BRANCH_NAME}")
|
||||
config.options.add("sonar.pullrequest.branch=${env.CHANGE_BRANCH}")
|
||||
config.options.add("sonar.pullrequest.provider=${config.pullRequestProvider}")
|
||||
switch(config.pullRequestProvider){
|
||||
case 'GitHub':
|
||||
@ -190,6 +190,7 @@ void call(Map parameters = [:]) {
|
||||
script: script,
|
||||
dockerImage: configuration.dockerImage
|
||||
){
|
||||
unstash 'git'
|
||||
worker(configuration)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user