Skip to content

Commit 9687165

Browse files
author
odx-pipelines/[email protected]
committed
fbt
1 parent 3e9d5df commit 9687165

28 files changed

+249
-2
lines changed

AIO.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
All in One reference for samples - In Alphabetical (A to Z) order.
2-
-------
2+
-----
33

44
- Access resource with Private IP from OCI Build runner - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-pa-with-private-oke
55
- Build Caching - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-build-caching
@@ -27,4 +27,5 @@ All in One reference for samples - In Alphabetical (A to Z) order.
2727
- Invoke deployment pipeline on a container image upload - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-deployment-examples/oci-devops-deploy-on-imageupload
2828
- OCI Policy management using terraform - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-config-examples/oci_devops_policy_dg_terraform
2929
- Scanning code for vulnerabilities for Maven packages - https://github.com/oracle-devrel/oci-devops-examples/tree/main/oci-build-examples/oci-devops-vulnerability-audit-management
30+
- Trigger build-pipeline from OCI Code repo on file modifications . - https://github.com/oracle-devrel/oci-devops-examples/blob/main/oci-coderepo-examples/oci-devops-coderepo-filebasedtrigger
3031

oci-build-examples/oci-devops-pa-with-private-oke/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This sample shows how to access resources which are with private IP addresses fr
2727

2828
## Procedure to use this illustration.
2929

30-
###OCI Notifications
30+
### OCI Notifications
3131
- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic
3232

3333
### OCI Container Engine for Kubernetes (OKE)

oci-coderepo-examples/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
All about OCI devops coderepo samples ..
22
=======
33

4+
<details>
5+
<summary>File based trigger of the buildpipeline. - click to expand</summary>
6+
7+
* [Trigger build-pipeline from OCI code repo.](./oci-devops-coderepo-filebasedtrigger/)
8+
9+
</details>
10+
411
<details>
512
<summary>Integration with external code repos. - click to expand</summary>
613

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
## Sample of **File-based Trigger Trigger** - Trigger an OCI DevOps Build pipeline based on a file/s update.
2+
3+
4+
In Oracle Cloud Infrastructure (OCI) DevOps, a build run can be automatically triggered when you commit your changes to a code repository.
5+
6+
You can control the trigger action by specifying the modified files in your repository to be included or excluded during the build run. The file-based trigger action is applicable only for the **Push** event.
7+
8+
9+
### File-Based Trigger
10+
For triggering a build run based on file changes, the following two options are provided:
11+
12+
**Files to include**: By default, changes to all files in the repository are included when a build run is triggered. The Files to include option allows you to specify a list of files and directories in the repository that you have changed and for which you want to trigger a build run. Files are specified using glob patterns. Trigger action is based on the changes affecting at least one of the included files.
13+
14+
**Files to exclude**: By default, changes to all files in the repository are included when a build run is triggered. The Files to exclude option allows you to specify a list of files and directories in the repository that you want to exclude from the build run. Files are specified using glob patterns. Changes affecting only the excluded files do not trigger a build. If files are specified for both include and exclude, then the exclude filter is applied to the output of the include filter.
15+
16+
17+
#### Objectives
18+
19+
- Create an OCI DevOps project and code repo.
20+
- Create an OCI DevOps build pipeline and trigger.
21+
- Setup file include /exclude conditions and test.
22+
23+
* Specific instruction to clone only this example.
24+
25+
```
26+
$ git init oci-devops-coderepo-filebasedtrigger
27+
$ cd oci-devops-coderepo-filebasedtrigger
28+
$ git remote add origin https://github.com/oracle-devrel/oci-devops-examples
29+
$ git config core. sparsecheckout true
30+
$ echo "oci-coderepo-examples/oci-devops-coderepo-filebasedtrigger/*">>.git/info/sparse-checkout
31+
$ git pull --depth=1 origin main
32+
33+
```
34+
35+
### Procedure
36+
37+
#### OCI Notifications.
38+
39+
- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic
40+
41+
42+
#### OCI Identity setups.
43+
44+
- Create a dynamic group and add below rules. -
45+
46+
```java
47+
ALL {resource.type = 'devopsbuildpipeline', resource.compartment.id = 'COMPARMENT OCID'}
48+
ALL {resource.type = 'devopsrepository', resource.compartment.id = 'COMPARMENT OCID'}
49+
```
50+
51+
- Create a policy with the below statements.
52+
53+
```java
54+
Allow dynamic-group "NAME OF THE DynamicGroup" to manage repos in compartment "COMPARTMENT NAME"
55+
Allow dynamic-group "NAME OF THE DynamicGroup" to use ons-topics in compartment "COMPARTMENT NAME"
56+
```
57+
#### OCI DevOps setups.
58+
59+
- Create a DevOps project and associate it with the notification topic - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm
60+
61+
![](images/oci-devops-project.png)
62+
63+
- Ensure to enable logging for the projects.
64+
65+
![](images/oci-devops-logs.png)
66+
67+
- Create an OCI Code repo - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm
68+
69+
![](images/oci-code-repo.png)
70+
71+
- Push the content to the code repo created. You may use [SSH based authorization](https://docs.oracle.com/en-us/iaas/Content/devops/using/clone_repo.htm#ssh_auth) or [HTTPS based authorization](https://docs.oracle.com/en-us/iaas/Content/devops/using/clone_repo.htm#https_auth).
72+
73+
![](images/oci-devops-corerepo-file.png)
74+
75+
76+
- Create a new build pipeline - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm
77+
78+
![](images/oci-devops-buildpipeline.png)
79+
80+
- Within the build pipeline, add a Managed Build stage - https://docs.oracle.com/en-us/iaas/Content/devops/using/add_buildstage.htm
81+
82+
![](images/oci-add-stage.png)
83+
84+
- Provide a name and description.
85+
86+
![](images/oci-buildstage-1.png)
87+
88+
- Use select within Primary code repository and select the OCI Code repo created.
89+
90+
![](images/oci-buildstage-2.png)
91+
92+
- Click Add and save the stage.
93+
94+
![](images/oci-buildstage-3.png)
95+
96+
97+
- Create a new DevOps trigger - https://docs.oracle.com/en-us/iaas/Content/devops/using/trigger_build.htm
98+
99+
- Provide a name and optional description.
100+
-
101+
![](images/oci-devops-trigger-1.png)
102+
103+
- Select the OCI code repository as the Source connection.
104+
105+
![](images/oci-devops-trigger-2.png)
106+
107+
- Select the code repository.
108+
109+
![](images/oci-devops-trigger-3.png)
110+
111+
- Click on Add action and select the build pipeline created.
112+
113+
![](images/oci-devops-trigger-4.png)
114+
115+
- Select the Event as Push. Fill the Build run conditions.
116+
117+
118+
#### OCI DevOps trigger conditions.
119+
120+
- **Note** - Build run conditions
121+
122+
- For the Push event, you can trigger the build run by specifying the source branch name and the files to be included or excluded in the build run.
123+
- (Optional) Enter the source repository branch on which the selected event triggers the build run.
124+
- If you select one of the Pull Request events, then you can also select the target code repository branch.
125+
- (Optional) Enter files to include for the trigger action. Files are specified using glob patterns.
126+
- For example, src/**/*.txt includes all text files in the "src" folder.
127+
- (Optional) Enter files to exclude the trigger action. Files are specified using glob patterns.
128+
- For example, **.html excludes all HTML files. For more examples and details.
129+
- Refer more for **Glob Patterns** - https://docs.oracle.com/en-us/iaas/Content/devops/using/glob-patterns.htm
130+
131+
- In this sample, we will be adding the below conditions.
132+
- Source branch: main / It's optional.
133+
- File to include : *.json and dire1/*.json / Update ona file with extension .json will trigger the build pipeline.
134+
- Files to exclude : *.yaml / For a sample, we will exclude yaml file updates
135+
136+
![](images/oci-devops-build-conditions.png)
137+
138+
- Click create and save the trigger.
139+
140+
![](images/oci-devops-trigger-conditions.png)
141+
142+
143+
#### Test the conditions .
144+
145+
- Using cloud shell or local machine, add a new value to [file. json](file. json)
146+
147+
![](images/oci-devops-trigger-json-test.png)
148+
149+
- This will trigger a build run and once completed, you may see the changes in the executions logs.
150+
151+
![](images/oci-build-log-view.png)
152+
153+
- To test the exclusion, update a value with the file. yaml and validate that there is NO execution.
154+
- You can set up different trigger conditions and validate.
155+
156+
![](images/oci-trigger-edit.png)
157+
158+
- Add new conditions, as an example here we are including all the files starting with `f` or `r` with any `extension` with the parent directory and excluding the `*.md` file. Once set up, update the files, push them to the code repo and validate the conditions.
159+
160+
![](images/oci-trigger-new-conditions.png)
161+
162+
163+
Contributors
164+
===========
165+
166+
- Author: Rahul M R.
167+
- Collaborators: NA
168+
- Last release: September 2022
169+
170+
Back to examples.
171+
----
172+
173+
- 🍿 [Back to OCI Devops Coderepo sample](./../README.md)
174+
- 🏝️ [Back to OCI Devops sample](./../../README.md)
175+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: 0.1
2+
component: build
3+
timeoutInSeconds: 6000
4+
runAs: root
5+
shell: bash
6+
env:
7+
# these are local variables to the build config
8+
variables:
9+
10+
# the value of a vaultVariable is the secret-id (in OCI ID format) stored in the OCI Vault service
11+
# you can then access the value of that secret in your build_spec.yaml commands
12+
vaultVariables:
13+
14+
# exportedVariables are made available to use as parameters in sucessor Build Pipeline stages
15+
# For this Build to run, the Build Pipeline needs to have a BUILDRUN_HASH parameter set
16+
exportedVariables:
17+
18+
19+
#Its a native way to fetch artifacts from external or artifact repo or a file path to use before a stage.
20+
# More about buildspec formats - https://docs.oracle.com/en-us/iaas/Content/devops/using/build_specs.htm
21+
22+
#inputArtifacts:
23+
24+
steps:
25+
- type: Command
26+
name: "Sample steps"
27+
timeoutInSeconds: 40
28+
command: |
29+
cd ${OCI_PRIMARY_SOURCE_DIR}
30+
echo "Running a build run based on file trigger"
31+
echo ".......The files changed are ........"
32+
git show --stat --oneline HEAD
33+
34+
onFailure:
35+
- type: Command
36+
command: |
37+
echo "Handling Failure"
38+
echo "Failure successfully handled"
39+
timeoutInSeconds: 40
40+
runAs: root
41+
42+
43+
#outputArtifacts:
44+
# - name: golan_app_base_image
45+
# type: DOCKER_IMAGE
46+
# # this location tag doesn't effect the tag used to deliver the container image
47+
# # to the Container Registry
48+
# location: golan_app_base:latest
49+
#
50+
# - name: golan_kube_manifest
51+
# type: BINARY
52+
# # this location tag doesn't effect the tag used to deliver the container image
53+
# # to the Container Registry
54+
# location: ${OCI_PRIMARY_SOURCE_DIR}/deployment_manifest.yaml
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"key": "value2"
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"key": "value",
3+
"attribute": "attr",
4+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
value: "test"
2+
attribute: "attr1"
67.8 KB
Loading

0 commit comments

Comments
 (0)