Skip to content

Commit b8ceb71

Browse files
authored
Display file content in tutorials (#25)
1 parent 2926b46 commit b8ceb71

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

docs/examples/jenkins/ansible-kubernetes/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,24 @@ First, create a new pipeline via [New Item](http://localhost:8080/view/all/newJo
2929

3030
In the configure pipeline view, scroll to the bottom and under Pipeline sub-header select `Pipeline script from SCM`. SCM type should be `Git` and Repository URL the url of this repository: `https://github.com/kangasta/cicd-examples.git`. Ensure that branch specifier includes `main` branch of the repository and modify the Script Path to be `docs/examples/jenkins/ansible-kubernetes/Jenkinsfile`.
3131

32+
The pipeline deploys an example application to a Kubernetes cluster using Ansible playbook. The playbook selects a container image tag based on Jenkins build parameter.
33+
34+
```groovy title="Jenkinsfile"
35+
---8<--- "docs/examples/jenkins/ansible-kubernetes/Jenkinsfile"
36+
```
37+
3238
After you have created the pipeline, try to execute it by clicking _Build Now_. The pipeline should have deployed the example application into the Kubernetes cluster with the default image tag (`cow`) defined in the [deploy-to-kubernetes.yml](./deploy-to-kubernetes.yml) Ansible playbook.
3339

40+
```yaml title="deploy-to-kubernetes.yml"
41+
---8<--- "docs/examples/jenkins/ansible-kubernetes/deploy-to-kubernetes.yml"
42+
```
43+
44+
After the Ansible playbook has been executed, the pipeline runs [wait-until-service-up.sh](./wait-until-service-up.sh) script. The script waits until the load-balancer created by the Kubernetes service has reached running state and parses the URL where the example application is running.
45+
46+
```sh
47+
---8<--- "docs/examples/jenkins/ansible-kubernetes/wait-until-service-up.sh"
48+
```
49+
3450
You can find the URL of the created load-balancer from the console output of the build. Open the application with your browser or user curl to see the application response.
3551

3652
In addition, after the first execution Jenkins should have updated the project configuration to contain parameters defined in the pipeline and we can configure the image tag in _Build with Parameters_ menu.

docs/examples/jenkins/build-status-pipelines/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,43 @@ node {
2424
```
2525

2626
The execution will likely fail with `ERROR: script not yet approved for use` message. To enable this script, navigate to [Manage Jenkins > In-process Script Approval](http://localhost:8080/scriptApproval/), inspect the script, and click _Approve_. Then try to run the created seed project again. It should now succeed and list the created resources.
27+
28+
The scripted pipeline listed above executes [jobs.groovy](./jobs.groovy) script. This script creates five new pipelines and executes four of those.
29+
30+
```groovy title="jobs.groovy"
31+
---8<--- "docs/examples/jenkins/build-status-pipelines/jobs.groovy"
32+
```
33+
34+
The four different pipeline scripts used to create the jobs are listed below. The final job, `Status/Not built`, uses the same script as `Status/Success`, but the build is not executed.
35+
36+
=== "Aborted"
37+
38+
Defines a pipeline that has a three minute timeout and build step that takes more than three minutes.
39+
40+
```groovy title="aborted.Jenkinsfile"
41+
---8<--- "docs/examples/jenkins/build-status-pipelines/aborted.Jenkinsfile"
42+
```
43+
44+
=== "Failed"
45+
46+
Defines a pipeline with single `sh` step that produces a non-zero exit code.
47+
48+
```groovy title="failed.Jenkinsfile"
49+
---8<--- "docs/examples/jenkins/build-status-pipelines/failed.Jenkinsfile"
50+
```
51+
52+
=== "Success"
53+
54+
Defines a pipeline with single succeeding `sh` step.
55+
56+
```groovy title="success.Jenkinsfile"
57+
---8<--- "docs/examples/jenkins/build-status-pipelines/success.Jenkinsfile"
58+
```
59+
60+
=== "Unstable"
61+
62+
Defines a pipeline with single `unstable` step.
63+
64+
```groovy title="unstable.Jenkinsfile"
65+
---8<--- "docs/examples/jenkins/build-status-pipelines/unstable.Jenkinsfile"
66+
```

docs/examples/jenkins/parallel-robot-pipeline/README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,41 @@ First, create a new pipeline via _[New Item](http://localhost:8080/view/all/newJ
1818

1919
In the configure pipeline view, scroll to the bottom and under Pipeline sub-header select `Pipeline script from SCM`. SCM type should be `Git` and Repository URL the url of this repository: `https://github.com/kangasta/cicd-examples.git`. Ensure that branch specifier includes `main` branch of the repository and modify the Script Path to be `docs/examples/jenkins/parallel-robot-pipeline/Jenkinsfile`.
2020

21-
After you have created the pipeline, try to execute it by clicking _Build Now_. All Robot Framework tasks should be in Skipped state as we did not specify URL variable, see `.robot` file for details. In addition, after the first execution Jenkins should have updated the project configuration to contain parameters defined in the pipeline and we can now pass target URL to our automation tasks in Build with Parameters menu.
21+
The pipeline executes the same Robot Framework suite twice: once with Firefox and once with Chromium. This is done in parallel. After the test suites have finished, the log files are combined in the next stage.
22+
23+
```groovy title="Jenkinsfile"
24+
---8<--- "docs/examples/jenkins/parallel-robot-pipeline/Jenkinsfile"
25+
```
26+
27+
After you have created the pipeline, try to execute it by clicking _Build Now_. All Robot Framework tasks should be in Skipped state as we did not specify an URL variable. In addition, after the first execution Jenkins should have updated the project configuration to contain parameters defined in the pipeline and we can now pass target URL to our automation tasks in _Build with Parameters_ menu.
28+
29+
The Robot Framework suite defined in [suites/screenshot.robot](./suites/screenshot.robot) uses Browser library to take a screenshot of the page available in the URL defined with the URL variable.
30+
31+
```robot title="suites/screenshot.robot"
32+
---8<--- "docs/examples/jenkins/parallel-robot-pipeline/suites/screenshot.robot"
33+
```
2234

2335
Finally, If the robot log cannot be loaded after task execution, see [this stackoverflow post](https://stackoverflow.com/questions/36607394/error-opening-robot-framework-log-failed) for solution. To summarize, run following command in Jenkins Script Console to modify Jenkins servers Content Security Policy (CSP):
2436

2537
```groovy
2638
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","sandbox allow-scripts; default-src 'none'; img-src 'self' data: ; style-src 'self' 'unsafe-inline' data: ; script-src 'self' 'unsafe-inline' 'unsafe-eval' ;")
2739
```
2840

29-
## Running the example scripts locally
41+
## Building and running the Docker container
42+
43+
The Jenkins pipeline listed above uses container image from Github Container Registry to run the pipelines. The container image is created using [Dockerfile](./Dockerfile) defined by this tutorial.
44+
45+
```Dockerfile title="Dockerfile"
46+
---8<--- "docs/examples/jenkins/parallel-robot-pipeline/Dockerfile"
47+
```
48+
49+
The Dockerfile is based on Playwright image that contains the Browser binaries and other Playwright related dependencies of the Browser library. In addition, the Dockerfile installs Python and Python libraries defined in [requirements.txt](./requirements.txt) to the container image.
50+
51+
```txt title="requirements.txt"
52+
---8<--- "docs/examples/jenkins/parallel-robot-pipeline/requirements.txt"
53+
```
54+
55+
## Running the tasks locally
3056

3157
Build the Docker containers with `docker build`:
3258

0 commit comments

Comments
 (0)