Skip to content

Commit d50d6c1

Browse files
authored
Merge pull request #4 from oracle-devrel/cascaded-pipelines
Cascaded pipeline samples with in the same region
2 parents 117a2c1 + 3e32c9b commit d50d6c1

31 files changed

+3888
-0
lines changed

oci-pipeline-examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ All about devops pipelines using OCI Devops.
77

88
* [Build and run a OCI devops pipeline with JAVA and Graal VM framework.](./oci-java-graalvm-devops-example/)
99

10+
</details>
11+
<details>
12+
<summary>Cascaded Pipelines - click to expand</summary>
13+
14+
* [Cascaded Pipelines - With in the Region](./oci-cascaded-pipelines/same-region/)
15+
1016
</details>
1117

1218

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# OCI DevOps Cascaded Pipelines
2+
3+
## Objective
4+
* Invocation of new another build or deploy pipeline after the successful execution of build/deploy pipeline.
5+
6+
## Prerequisites & References
7+
This guide assumes that you already have required pipelines created to invoke them cascadly. You may refer to below links to create and setup pipelines.
8+
* Reference Architecture - https://github.com/oracle-quickstart/oci-arch-ci-cd-devops
9+
* Oracle DevOps Documentation - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm
10+
* IAM Policies - https://docs.oracle.com/en-us/iaas/Content/devops/using/devops_iampolicies.htm
11+
12+
## Samples
13+
14+
Sample procedure and code snippets for the cascaded pipelines of the below scenarios.
15+
16+
* [Trigger Build Pipeline from Build Pipeline](same-region/trigger-build-from-build)
17+
* [Trigger Deploy Pipeline from Build Pipeline](same-region/trigger-deploy-from-build)
18+
* [Trigger Build Pipeline from Deploy Pipeline](same-region/trigger-build-from-deploy)
19+
* [Trigger Deploy Pipeline from Deploy Pipeline](same-region/trigger-deploy-from-deploy)
20+
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# OCI DevOps Cascaded Pipelines - Same Region
2+
3+
## Objective
4+
* Invocation of another build or deploy pipeline after the successful execution of build/deploy pipeline.
5+
6+
## Prerequisites & References
7+
This guide assumes that you already have required pipelines created to invoke them cascadly. You may refer to below links to create and setup pipelines.
8+
* Reference Architecture - https://github.com/oracle-quickstart/oci-arch-ci-cd-devops
9+
* Oracle DevOps Documentation - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm
10+
* IAM Policies - https://docs.oracle.com/en-us/iaas/Content/devops/using/devops_iampolicies.htm
11+
12+
## Samples
13+
14+
Sample procedure and code snippets for the cascaded pipelines of the below scenarios.
15+
16+
* [Trigger Build Pipeline from Build Pipeline](trigger-build-from-build)
17+
* [Trigger Deploy Pipeline from Build Pipeline](trigger-deploy-from-build)
18+
* [Trigger Build Pipeline from Deploy Pipeline](trigger-build-from-deploy)
19+
* [Trigger Deploy Pipeline from Deploy Pipeline](trigger-deploy-from-deploy)
20+
21+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# OCI DevOps Cascaded Pipelines
2+
3+
## Trigger Build Pipeline from Build Pipeline
4+
5+
### Prerequisites
6+
* Two build pipelines
7+
8+
#### 1. Deploy Function
9+
**Step 1:**
10+
Clone the repository code.
11+
```
12+
$ git init cascaded-pipelines
13+
$ cd cascaded-pipelines
14+
$ git remote add origin https://github.com/oracle-devrel/oci-devops-examples
15+
$ git config core.sparsecheckout true
16+
$ echo "oci-pipeline-examples/oci-cascaded-pipelines/same-region/trigger-build-from-build/*">>.git/info/sparse-checkout
17+
$ git pull --depth=1 origin main
18+
```
19+
20+
**Step 2:**
21+
Change to function directory.
22+
```
23+
$ cd node-function
24+
```
25+
26+
**Step 3:**
27+
In `func.yaml`, update `build_pipeline_id` and `display_name_prefix_for_new_run` with appropriate values as below.
28+
29+
```
30+
config:
31+
build_pipeline_id: "<BUILD-PIPELINE-OCID>"
32+
display_name_prefix_for_new_run: "AutoTriggeredCascade2_"
33+
```
34+
35+
**Step 4:**
36+
Deploy the function with below command.
37+
```
38+
$ fn -v deploy --app <app-name>
39+
```
40+
Note: Refer https://docs.oracle.com/en-us/iaas/Content/Functions/Tasks/functionscreatingapps.htm for creating new application.
41+
42+
#### 2. Configure Service Connector Hub
43+
**Step 1:**
44+
45+
Open Menu > `Observability & Management` > `Service Connectors`
46+
47+
**Step 2:**
48+
49+
Set Service Connector Source as `Logging` and Target as `Functions`
50+
51+
**Step 3:**
52+
53+
Configure Source as below
54+
55+
![Service Connector Source Config](images/service-connector-source-config.png)
56+
57+
* Choose Compartment, Log Group, Logs of your DevOps Project.
58+
* set `data.buildPipelineId` to the previous pipeline OCID as above.
59+
* set `data.message` to the last successful unique log message like `Completed Build stage.`
60+
61+
**Step 4:**
62+
63+
Configure Target with `Function Application` and `Function` as `trigger-build-pipeline-from-build-pipeline` as below
64+
65+
![Service Connector Target Config](images/service-connector-target-config.png)
66+
Loading
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const fdk = require('@fnproject/fdk');
2+
const common = require("oci-common");
3+
const devops = require("oci-devops");
4+
5+
const buildPipelineId = process.env.build_pipeline_id;
6+
const displayNamePrefixForNewRun = process.env.display_name_prefix_for_new_run;
7+
8+
fdk.handle(async function(input){
9+
const provider = common.ResourcePrincipalAuthenticationDetailsProvider.builder();
10+
11+
const devopsClient = new devops.DevopsClient({
12+
authenticationDetailsProvider: provider
13+
})
14+
const run = await devopsClient.getBuildRun({buildRunId: input[0].data.buildRunId});
15+
console.log("CURRENT BUILD RUN", JSON.stringify(run));
16+
17+
var items = run.buildRun.buildOutputs.exportedVariables.items;
18+
19+
// Add new parameters if required
20+
// items.push({name: 'PARAM', value: 'Value'});
21+
22+
const buildRunResponse = await devopsClient.createBuildRun({
23+
createBuildRunDetails: {
24+
buildPipelineId,
25+
displayName: displayNamePrefixForNewRun + new Date().toISOString(),
26+
buildRunArguments: {
27+
items
28+
}
29+
}
30+
})
31+
console.log("CREATE BUILD RUN RESPONSE", JSON.stringify(buildRunResponse));
32+
33+
return buildRunResponse;
34+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
schema_version: 20180708
2+
name: trigger-build-pipeline-from-build-pipeline
3+
version: 0.0.10
4+
runtime: node
5+
build_image: fnproject/node:14-dev
6+
run_image: fnproject/node:14
7+
entrypoint: node func.js
8+
config:
9+
build_pipeline_id: "<BUILD-PIPELINE-OCID>"
10+
display_name_prefix_for_new_run: "AutoTriggeredCascade2_"

0 commit comments

Comments
 (0)