Skip to content

Commit ee405c7

Browse files
oiavorskyimarcingrzejszczak
authored andcommitted
Fixes for minor defects with Jenkins flavor of the pipeline (#148)
* Improve support for Git SSH key with local Jenkins The jenkins/start.sh now recognizes option -key <path_to_private_key> and uses it to create the SSH Git credentials when starting new local Jenkins instance for the first time. The #137 is fixed by adding missed argument to the jenkins/Dockerfile. Also the documentation now reflects the additional parameter to start.sh * Fix #134 by using OS-specific file path separator * Fix #138 by encapsulating SCM config in one place Added a unit test to reproduce the issue and refactored logic in the jenkins_pipeline_sample.groovy to use the new extension function to configure SCM block for all jobs. * Fix #141 Fixed typos in the marker of the end of the K8S block for removal. Fixed pipeline tests to not assume existence of either K8S or CF scripts. Fixed JobScripts tests to only verify availability of the CF/K8S jobs in case of them not being excluded during the customization. * Convert the code in fixes to be type-safe
1 parent fedec2c commit ee405c7

File tree

15 files changed

+208
-168
lines changed

15 files changed

+208
-168
lines changed

README.adoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
15531553
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
15541554
contain your GitHub org in which you have the forked repos.
15551555

1556+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
1557+
if you prefer to use the key-based authentication with your Git repositories.
1558+
15561559
[[deploy-infra-cf]]
15571560
===== Deploy the infra JARs to Artifactory
15581561

@@ -1879,6 +1882,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
18791882
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
18801883
contain your GitHub org in which you have the forked repos.
18811884

1885+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
1886+
if you prefer to use the key-based authentication with your Git repositories.
1887+
18821888
You need to pass the credentials for the Docker organization (by default we will
18831889
search for the Docker images at Docker Hub) so that the pipeline will be able
18841890
to push images to your org.
@@ -5366,4 +5372,4 @@ version of the release.
53665372
docker login
53675373
docker build -t springcloud/spring-cloud-pipeline-jenkins:<version> ./jenkins
53685374
docker push springcloud/spring-cloud-pipeline-jenkins:<version>
5369-
----
5375+
----

buildSrc/src/test/groovy/org/springframework/cloud/pipelines/ProjectCustomizerSpec.groovy

+22-16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import spock.lang.Specification
99

1010
import org.springframework.boot.test.rule.OutputCapture
1111

12+
import java.util.regex.Matcher
13+
1214
/**
1315
* @author Marcin Grzejszczak
1416
*/
@@ -59,15 +61,15 @@ class ProjectCustomizerSpec extends Specification {
5961
then:
6062
String logs = capture.toString()
6163
//
62-
!logs.contains("buildSrc/foo.bash")
64+
!logs.contains(filePath("buildSrc/foo.bash"))
6365
// we want to remove only Concourse stuff
64-
!logs.contains("/jenkins,")
65-
logs.contains("images/concourse")
66-
logs.contains("CONCOURSE.adoc")
67-
logs.contains("CF_DEMO.adoc")
68-
logs.contains("CF_JENKINS")
69-
logs.contains("tools/cf-helper")
70-
logs.contains("bash/pipeline-cf")
66+
!logs.contains(filePath("/jenkins,"))
67+
logs.contains(filePath("images/concourse"))
68+
logs.contains(filePath("CONCOURSE.adoc"))
69+
logs.contains(filePath("CF_DEMO.adoc"))
70+
logs.contains(filePath("CF_JENKINS"))
71+
logs.contains(filePath("tools/cf-helper"))
72+
logs.contains(filePath("bash/pipeline-cf"))
7173
logs.contains("Removing lines")
7274
logs.contains("Removing files")
7375
and:
@@ -90,15 +92,15 @@ class ProjectCustomizerSpec extends Specification {
9092
then:
9193
String logs = capture.toString()
9294
//
93-
!logs.contains("buildSrc/foo.bash")
95+
!logs.contains(filePath("buildSrc/foo.bash"))
9496
// we want to remove only Concourse stuff
95-
!logs.contains("/concourse,")
96-
logs.contains("images/jenkins")
97-
logs.contains("JENKINS.adoc")
98-
logs.contains("K8S_DEMO.adoc")
99-
logs.contains("K8S_JENKINS")
100-
logs.contains("tools/k8s-helper")
101-
logs.contains("bash/pipeline-k8s")
97+
!logs.contains(filePath("/concourse,"))
98+
logs.contains(filePath("images/jenkins"))
99+
logs.contains(filePath("JENKINS.adoc"))
100+
logs.contains(filePath("K8S_DEMO.adoc"))
101+
logs.contains(filePath("K8S_JENKINS"))
102+
logs.contains(filePath("tools/k8s-helper"))
103+
logs.contains(filePath("bash/pipeline-k8s"))
102104
logs.contains("Removing lines")
103105
logs.contains("Removing files")
104106
and:
@@ -109,4 +111,8 @@ class ProjectCustomizerSpec extends Specification {
109111
}
110112
}
111113

114+
String filePath(String canonicalPath) {
115+
return canonicalPath.replaceAll("/", Matcher.quoteReplacement(File.separator))
116+
}
117+
112118
}

buildSrc/src/test/resources/project_customizer/docs-sources/src/main/asciidoc/CF_JENKINS.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
6161
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
6262
contain your GitHub org in which you have the forked repos.
6363

64+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
65+
if you prefer to use the key-based authentication with your Git repositories.
66+
6467
[[deploy-infra-cf]]
6568
===== Deploy the infra JARs to Artifactory
6669

buildSrc/src/test/resources/project_customizer/docs-sources/src/main/asciidoc/K8S_JENKINS.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
6161
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
6262
contain your GitHub org in which you have the forked repos.
6363

64+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
65+
if you prefer to use the key-based authentication with your Git repositories.
66+
6467
You need to pass the credentials for the Docker organization (by default we will
6568
search for the Docker images at Docker Hub) so that the pipeline will be able
6669
to push images to your org.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test:
2+
services:
3+
- type: broker
4+
name: rabbitmq-github-webhook
5+
broker: foo
6+
plan: bar
7+
- type: broker
8+
name: mysql-github-webhook
9+
broker: foo
10+
plan: bar
11+
- type: app
12+
name: eureka-github-webhook
13+
coordinates: com.example.eureka:github-eureka:0.0.1.M1
14+
- type: stubrunner
15+
name: stubrunner
16+
coordinates: com.example.github:github-analytics-stub-runner-boot-classpath-stubs:0.0.1.M1
17+
pathToManifest: foo/manifest.yml
18+
stage:
19+
services:
20+
- type: broker
21+
name: github-rabbitmq
22+
broker: foo
23+
plan: bar
24+
- type: broker
25+
name: mysql-github
26+
broker: foo
27+
plan: bar
28+
- type: app
29+
name: github-eureka
30+
coordinates: com.example.eureka:github-eureka:0.0.1.M1

common/src/test/bats/pipeline.bats

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ teardown() {
2828
@test "yaml2json should convert valid YAML file to JSON" {
2929
source "${SOURCE_DIR}/pipeline.sh"
3030

31-
run yaml2json "${FIXTURES_DIR}/sc-pipelines-cf.yml"
31+
run yaml2json "${FIXTURES_DIR}/sc-pipelines-generic.yml"
3232

3333
assert_success
3434
}
@@ -42,24 +42,24 @@ teardown() {
4242
}
4343

4444
@test "deployServices should deploy services from pipeline descriptor" {
45-
export PIPELINE_DESCRIPTOR="sc-pipelines-k8s.yml"
45+
export PIPELINE_DESCRIPTOR="sc-pipelines-generic.yml"
4646
source "${SOURCE_DIR}/pipeline.sh"
4747

4848
cd "${FIXTURES_DIR}"
4949

5050
run deployServices
5151

5252
assert_success
53-
assert_line --index 0 'rabbitmq-github-webhook rabbitmq'
54-
assert_line --index 1 'mysql-github-webhook mysql'
55-
assert_line --index 2 'eureka-github-webhook eureka'
56-
assert_line --index 3 'stubrunner-github-webhook stubrunner'
53+
assert_line --index 0 'rabbitmq-github-webhook broker'
54+
assert_line --index 1 'mysql-github-webhook broker'
55+
assert_line --index 2 'eureka-github-webhook app'
56+
assert_line --index 3 'stubrunner stubrunner'
5757
}
5858

5959
@test "parsePipelineDescriptor should export an env var with parsed YAML" {
6060
source "${SOURCE_DIR}/pipeline.sh"
6161

62-
PIPELINE_DESCRIPTOR="${FIXTURES_DIR}/sc-pipelines-cf.yml"
62+
PIPELINE_DESCRIPTOR="${FIXTURES_DIR}/sc-pipelines-generic.yml"
6363

6464
assert_equal "${PARSED_YAML}" ""
6565

docs-sources/src/main/asciidoc/CF_JENKINS.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
6161
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
6262
contain your GitHub org in which you have the forked repos.
6363

64+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
65+
if you prefer to use the key-based authentication with your Git repositories.
66+
6467
[[deploy-infra-cf]]
6568
===== Deploy the infra JARs to Artifactory
6669

docs-sources/src/main/asciidoc/K8S_JENKINS.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
6161
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
6262
contain your GitHub org in which you have the forked repos.
6363

64+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
65+
if you prefer to use the key-based authentication with your Git repositories.
66+
6467
You need to pass the credentials for the Docker organization (by default we will
6568
search for the Docker images at Docker Hub) so that the pipeline will be able
6669
to push images to your org.

docs-sources/src/main/jekyll/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
* Clone the `spring-cloud-pipelines` project
127127
* Go to `jenkins` folder
128128
* Run `./start.sh yourGithubUser yourGithubPass yourGithubOrg` to start Jenkins and Artifactory (`yourGithubUser` and `yourGithubPass`
129-
are your Github credentials required by the pipeline to tag the forked repo that lays in `yourGithubOrg`)
129+
are your Github credentials required by the pipeline to tag the forked repo that lays in `yourGithubOrg`;
130+
you could also pass `-key path_to_private_key` if you prefer to use the key-based authentication with your Git repositories)
130131
* Run `./deploy_infra.sh` to upload to your Artifactory the infrastructure apps (`eureka` and `stub runner`)
131132
* Go to Jenkins and click the `jenkins-pipeline-seed` in order to generate the pipeline jobs
132133
* Go to the `github-webhook` pipeline view and click the `play` button to run the pipeline

docs/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
* Clone the `spring-cloud-pipelines` project
127127
* Go to `jenkins` folder
128128
* Run `./start.sh yourGithubUser yourGithubPass yourGithubOrg` to start Jenkins and Artifactory (`yourGithubUser` and `yourGithubPass`
129-
are your Github credentials required by the pipeline to tag the forked repo that lays in `yourGithubOrg`)
129+
are your Github credentials required by the pipeline to tag the forked repo that lays in `yourGithubOrg`;
130+
you could also pass `-key path_to_private_key` if you prefer to use the key-based authentication with your Git repositories)
130131
* Run `./deploy_infra.sh` to upload to your Artifactory the infrastructure apps (`eureka` and `stub runner`)
131132
* Go to Jenkins and click the `jenkins-pipeline-seed` in order to generate the pipeline jobs
132133
* Go to the `github-webhook` pipeline view and click the `play` button to run the pipeline

jenkins/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
FROM jenkins:2.19.1
77
ARG gituser=changeme
88
ARG gitpass=changeme
9+
ARG gitsshkey=changeme
910
ARG dockerRegistryOrg=changeme
1011
ARG dockerRegistryUser=changeme
1112
ARG dockerRegistryPass=changeme

jenkins/README.adoc

+7-1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
298298
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
299299
contain your GitHub org in which you have the forked repos.
300300

301+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
302+
if you prefer to use the key-based authentication with your Git repositories.
303+
301304
[[deploy-infra-cf]]
302305
===== Deploy the infra JARs to Artifactory
303306

@@ -624,6 +627,9 @@ any manual work on the Jenkins side. In the above parameters, the third paramete
624627
could be yourForkedGithubOrg or yourGithubUsername. Also the `REPOS` env variable will
625628
contain your GitHub org in which you have the forked repos.
626629

630+
Instead of the Git username and password parameters you could pass `-key <path_to_private_key>`
631+
if you prefer to use the key-based authentication with your Git repositories.
632+
627633
You need to pass the credentials for the Docker organization (by default we will
628634
search for the Docker images at Docker Hub) so that the pipeline will be able
629635
to push images to your org.
@@ -1268,4 +1274,4 @@ REUSE_CF_LOGIN=true ./tools/cf-helper.sh setup-prod-infra
12681274
```
12691275

12701276
This script will create the mysql db, rabbit mq service, download and deploy Eureka
1271-
to the space and organization you're logged into.
1277+
to the space and organization you're logged into.

0 commit comments

Comments
 (0)