Skip to content

Commit 3fc2b57

Browse files
committed
Cascaded pipeline samples with in the same region
1 parent eb727e7 commit 3fc2b57

30 files changed

+3830
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The service also provides private Git repositories to store your code and it sup
1515
- [OCI Devops Build service - samples](./oci-build-examples/README.md)
1616
- [OCI Devops Deployment service - samples](./oci-deployment-examples/README.md)
1717
- [OCI Source Code Management service - sample](./oci-coderepo-examples/README.md)
18+
- [OCI Cascaded Pipelines - sample](./oci-cascaded-pipelines/README.md)
1819

1920
## Instruction to clone a specific example.
2021

oci-cascaded-pipelines/README.md

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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 clone https://github.com/oracle-cloud-infra/oci-devops-cascaded-pipelines.git
13+
```
14+
15+
**Step 2:**
16+
Change to function directory.
17+
```
18+
$ cd oci-devops-cascaded-pipelines/same-region/trigger-build-from-build/node-function
19+
```
20+
21+
**Step 3:**
22+
In `func.js`, update `buildPipelineId` and `displayNamePrefixForNewRun` with appropriate values as below.
23+
24+
```
25+
const buildPipelineId = "<target-build-pipeline-ocid>"
26+
const displayNamePrefixForNewRun = "AutoTriggeredCascadedPipeline_";
27+
```
28+
29+
**Step 4:**
30+
Deploy the function with below command.
31+
```
32+
$ fn -v deploy --app <app-name>
33+
```
34+
35+
#### 2. Configure Service Connector Hub
36+
**Step 1:**
37+
38+
Open Menu > `Observability & Management` > `Service Connectors`
39+
40+
**Step 2:**
41+
42+
Set Service Connector Source as `Logging` and Target as `Functions`
43+
44+
**Step 3:**
45+
46+
Configure Source as below
47+
48+
![Service Connector Source Config](images/service-connector-source-config.png)
49+
50+
* Choose Compartment, Log Group, Logs of your DevOps Project.
51+
* set `data.buildPipelineId` to the previous pipeline OCID as above.
52+
* set `data.message` to the last successful unique log message like `Completed Build stage.`
53+
54+
**Step 4:**
55+
56+
Configure Target with `Function Application` and `Function` as `trigger-build-pipeline-from-build-pipeline` as below
57+
58+
![Service Connector Target Config](images/service-connector-target-config.png)
59+
439 KB
Loading
239 KB
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 = "ocid1.devopsbuildpipeline.oc1.ap-hyderabad-1.amaaaaaak56z2vqazjgskjqjjdjqowrdn3d6eatvhsixvhzb2ozoje2qxh7q"
6+
const displayNamePrefixForNewRun = "AutoTriggeredCascade2_";
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+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

0 commit comments

Comments
 (0)