Skip to content

Commit 41319c6

Browse files
authored
Merge pull request #22 from oracle-devrel/imagescan
build spec param
2 parents fa277c7 + e7d50b3 commit 41319c6

File tree

7 files changed

+151
-5
lines changed

7 files changed

+151
-5
lines changed

oci-build-examples/README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
All about OCI devops build samples ..
22
=======
3+
<details>
4+
<summary>Build Caching - click to expand</summary>
5+
6+
* [Speed up builds with caching](./oci-build-caching/)
7+
8+
</details>
39

410
<details>
5-
<summary>Security & Quality - click to expand</summary>
11+
<summary>Build Paramters - click to expand</summary>
612

7-
* [Integrate sonarqube with OCI devops build runner.](./oci_buildrunner_with_sonarqube/)
8-
* [Container image scanning before deploy.](./oci_imagescan_before_deploy/)
13+
* [All about predefined system variables](./oci_build_parameters/)
914

1015
</details>
1116

17+
1218
<details>
13-
<summary>Build Caching - click to expand</summary>
19+
<summary>Security & Quality - click to expand</summary>
1420

15-
* [Speed up builds with caching](./oci-build-caching/)
21+
* [Integrate sonarqube with OCI devops build runner.](./oci_buildrunner_with_sonarqube/)
22+
* [Container image scanning before deploy.](./oci_imagescan_before_deploy/)
1623

1724
</details>
1825

1926

27+
2028
### Back to examples.
2129
----
2230

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
## Sample illustration to user OCI DevOps Build pipeline's predefined system variables.
3+
4+
5+
## Predefined System Variables (of OCI Build pipeline stage)
6+
7+
DevOps provides a set of predefined system variables with default values that you can use like environment variables in the build specification. These values are available within DevOps managed build stages and can expose to other stages via an explicit export of the variables.
8+
You need to export these values with another variable name which is following below patters.
9+
10+
```markdown
11+
Parameter name can only consist of ASCII letter, digit or '_' (underscore) characters and not start with an oci (case-insensitive) prefix
12+
```
13+
14+
System Variables | Description |
15+
--- | --- |
16+
OCI_STAGE_ID | The OCID of the current stage. |
17+
OCI_PIPELINE_ID|The OCID of the current build pipeline.|
18+
OCI_BUILD_RUN_ID|The OCID of the current build run.|
19+
OCI_TRIGGER_COMMIT_HASH|Commit hash of the current trigger.|
20+
OCI_TRIGGER_SOURCE_BRANCH_NAME|Branch that triggers the build.|
21+
OCI_TRIGGER_SOURCE_URL|Repository URL that triggered the build|
22+
OCI_TRIGGER_EVENT_TYPE|Trigger that started the event.|
23+
OCI_PRIMARY_SOURCE_DIR|Default working directory of the build (primary source working directory).|
24+
OCI_WORKSPACE_DIR|Working directory value. Contains /workspace as the default value.|
25+
${OCI_WORKSPACE_DIR}/ "source-name"|Build source directory path."source-name" is the name of the build source given by the user while creating the Build stage.|
26+
OCI_BUILD_STAGE_NAME|Build stage name.|
27+
OCI_PRIMARY_SOURCE_NAME|Primary build source name.|
28+
OCI_PRIMARY_SOURCE_COMMIT_HASH|Primary build source commit hash used in the current build run.|
29+
OCI_PRIMARY_SOURCE_SOURCE_URL|Primary build source URL.|
30+
OCI_PRIMARY_SOURCE_SOURCE_BRANCH_NAME| Primary build source branch used in the current build run.|
31+
32+
Reference - https://docs.oracle.com/en-us/iaas/Content/devops/using/build_specs.htm
33+
34+
### Procedure to use the sample.
35+
36+
- Clone the sample illustrations.
37+
```
38+
$ git init oci_build_parameters
39+
$ cd oci_imagescan_before_deploy
40+
$ git remote add origin <url to this git repo>
41+
$ git config core. sparsecheckout true
42+
$ echo "oci-build-examples/oci_build_parameters/*">>.git/info/sparse-checkout
43+
$ git pull --depth=1 origin main
44+
45+
```
46+
- Create a DevOps project - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm
47+
- Create an OCI Code repo - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm
48+
- Create a build pipeline - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_buildpipeline.htm
49+
- Push these samples to the OCI Code repo.
50+
- Add a `Managed Build stage` to the build pipeline - https://docs.oracle.com/en-us/iaas/Content/devops/using/add_buildstage.htm
51+
- Run the build pipeline and verify the values.
52+
- You may use these values by defining an external repo (Github/Gitlab or Bitbucket) and validate the executions too - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_connection.htm
53+
54+
Sample output
55+
56+
----
57+
58+
59+
60+
#### Build Stage View (With a combination of OCI Code repo and Github.com repo)
61+
62+
![](images/buildview.png)
63+
64+
65+
#### Build logs for manual execution of build stage with OCI Code repo.
66+
67+
68+
![](images/logs_manual.png)
69+
70+
#### Build logs for an automated execution with a `Trigger`.
71+
72+
- using Github Repo
73+
74+
![](images/trigger_with_github.png)
75+
76+
- using OCI Code Repo
77+
78+
![](images/trigger_with_ocirepo.png)
79+
80+
Contributors
81+
===========
82+
83+
- Author: Rahul M R.
84+
- Collaborators: NA
85+
- Last release: June 2022
86+
87+
### Back to examples.
88+
----
89+
90+
- 🍿 [Back to OCI DevOps Build sample](./../README.md)
91+
- 🏝️ [Back to OCI Devops sample](./../../README.md)
92+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
code_repo_name: "whatever"
10+
11+
# the value of a vaultVariable is the secret-id (in OCI ID format) stored in the OCI Vault service
12+
# you can then access the value of that secret in your build_spec.yaml commands
13+
vaultVariables:
14+
# EXAMPLE_SECRET: "YOUR-SECRET-OCID"
15+
# exportedVariables are made available to use as parameters in sucessor Build Pipeline stages
16+
# For this Build to run, the Build Pipeline needs to have a BUILDRUN_HASH parameter set
17+
exportedVariables:
18+
- BUILDRUN_HASH
19+
20+
steps:
21+
- type: Command
22+
name: "Fetch Values"
23+
timeoutInSeconds: 240
24+
command: |
25+
echo "OCI_BUILD_RUN_ID => ${OCI_BUILD_RUN_ID}"
26+
echo "OCI_TRIGGER_COMMIT_HASH => ${OCI_TRIGGER_COMMIT_HASH}"
27+
echo "OCI_STAGE_ID =>${OCI_STAGE_ID}"
28+
echo "OCI_BUILD_RUN_ID=>${OCI_BUILD_RUN_ID}"
29+
echo "OCI_TRIGGER_SOURCE_BRANCH_NAME =>${OCI_TRIGGER_SOURCE_BRANCH_NAME} "
30+
echo "OCI_TRIGGER_SOURCE_URL =>${OCI_TRIGGER_SOURCE_URL} "
31+
echo "OCI_TRIGGER_EVENT_TYPE =>${OCI_TRIGGER_EVENT_TYPE} "
32+
echo "OCI_PRIMARY_SOURCE_DIR =>${OCI_PRIMARY_SOURCE_DIR} "
33+
echo "OCI_WORKSPACE_DIR => ${OCI_WORKSPACE_DIR} "
34+
echo "OCI_PRIMARY_SOURCE_NAME => ${OCI_PRIMARY_SOURCE_NAME} "
35+
echo "OCI_BUILD_STAGE_NAME => ${OCI_BUILD_STAGE_NAME}"
36+
echo "Use a custom value from predefined system variable to expose outside of the current build stage.."
37+
export BUILDRUN_HASH =`echo ${OCI_BUILD_RUN_ID} | rev | cut -c 1-7`
38+
if [ -z ${OCI_TRIGGER_COMMIT_HASH} ]
39+
then
40+
cd ${OCI_PRIMARY_SOURCE_DIR}
41+
export OCI_TRIGGER_COMMIT_HASH=`git log --format="%H" -n 1|cut -c 1-7`
42+
fi
43+
echo "OCI_TRIGGER_COMMIT_HASH =>${OCI_TRIGGER_COMMIT_HASH}"
44+
45+
# Last command is used to get the commit hash using GIT ID ,its a hack while there wont be any default commit hash by manual Run.
46+
# Until its fixed we can fetch the same via GIT Command.
148 KB
Loading
66.4 KB
Loading
78.9 KB
Loading
78.7 KB
Loading

0 commit comments

Comments
 (0)