|
| 1 | +A way (workaround) to execute commands on to a Windows machine using OCI Run command agent from OCI Build Pipeline |
| 2 | +------ |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +Objective |
| 7 | +--- |
| 8 | +- Create an OCI DevOps build pipeline. |
| 9 | +- Create a windows host and enable compute run agent. |
| 10 | +- Execute commands on Windows hosts and fetch the result. |
| 11 | + |
| 12 | + ``` |
| 13 | + $ git init oci-devops-connect-to-windows-from-buildmachines |
| 14 | + $ cd oci-devops-connect-to-windows-from-buildmachines |
| 15 | + $ git remote add origin <url to this git repo> |
| 16 | + $ git config core.sparsecheckout true |
| 17 | + $ echo "oci-build-examples/oci-devops-connect-to-windows-from-buildmachines/*">>.git/info/sparse-checkout |
| 18 | + $ git pull --depth=1 origin main |
| 19 | +
|
| 20 | + ``` |
| 21 | + |
| 22 | +Audience: OCI Advanced users. |
| 23 | + |
| 24 | +Procedure to use the illustration |
| 25 | +------- |
| 26 | + |
| 27 | +### Compute instance. |
| 28 | + |
| 29 | +- Create an OCI Compute instance with Windows operating system. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +- Provide `VCN`, and `Subnet` information. A public IP address is optional, as we will be using the `OCI Run command agent` it does not need a public IP address for the connection. |
| 36 | + |
| 37 | +- Ensure that the `Compute Instance Run command` agent is enabled. |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +### OCI identity setup. |
| 42 | + |
| 43 | +- Create a dynamic group for computing instance/s with the below rule. |
| 44 | +```java |
| 45 | +All {instance.compartment.id = 'OCID OF WINDOWS HOST'} |
| 46 | +``` |
| 47 | +- Create a dynamic group for the DevOps build pipeline with the below rule. |
| 48 | + |
| 49 | +```java |
| 50 | +ALL {resource.type = 'devopsbuildpipeline', resource.compartment.id = 'OCID OF OCI COMPARTMENT'} |
| 51 | +``` |
| 52 | + |
| 53 | +- Create the below identity policies. |
| 54 | +```java |
| 55 | +Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> to manage objects in compartment <NAME OF THE COMPARTMENT> |
| 56 | + |
| 57 | +Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> to manage ons-topics in compartment <NAME OF THE COMPARTMENT> |
| 58 | + |
| 59 | +Allow dynamic-group <NAME OF THE DG FOR BUILD PIPELINE> ons-topics in compartment <NAME OF THE COMPARTMENT> |
| 60 | + |
| 61 | +Allow dynamic-group <NAME OF THE DG FOR COMPUTE INSTANCES> to use instance-agent-command-execution-family in compartment <NAME OF THE COMPARTMENT> |
| 62 | + |
| 63 | +Allow dynamic group <NAME OF THE DG FOR COMPUTE INSTANCES> to manage objects in compartment <NAME OF THE COMPARTMENT> |
| 64 | + |
| 65 | +Allow dynamic-group <NAME OF THE DG FOR COMPUTE INSTANCES> to use instance-agent-command-execution-family in compartment <NAME OF THE COMPARTMENT> |
| 66 | + |
| 67 | +``` |
| 68 | + |
| 69 | +### Object Storage. |
| 70 | + |
| 71 | +- Create an `object storage bucket. |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +### OCI DevOps. |
| 77 | +- Create an OCI notification topic - https://docs.oracle.com/en-us/iaas/Content/Notification/Tasks/managingtopicsandsubscriptions.htm#createTopic |
| 78 | + |
| 79 | +- Create a DevOps project - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_project.htm#create_a_project |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +- Enable logging for the DevOps project. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +Click on Code Repository within the DevOps project resource and click on `Create repository. - https://docs.oracle.com/en-us/iaas/Content/devops/using/create_repo.htm |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +- Using the `ssh` or `https` method and push the whole content to the OCI Code repo - refer to details here - https://docs.oracle.com/en-us/iaas/Content/devops/using/clone_repo.htm |
| 92 | + |
| 93 | +- Click on Build pipelines within DevOps project resources and click on Create build pipeline- https://docs.oracle.com/en-us/iaas/Content/devops/using/managing_build_pipelines.htm |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +- Use `+` and add a stage. |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +- Add a `Managed Build stage`. |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +- Provide the details and connect to the `OCI Code repo` as the primary source name. |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +- Click `Add`. |
| 110 | + |
| 111 | +- Add below `Build parameters` and actual values. |
| 112 | + |
| 113 | +```java |
| 114 | +- OBJECTSTORAGE_NAMESPACE: OBJECT STORAGE NAMESPACE |
| 115 | +- OBJECTSTORAGE_BUCKET: OBJECT BUCKET NAME |
| 116 | +- INSTANCE_OCID : COMPUTE INSTANCE(WINDOWS) OCID |
| 117 | +- OCI_REGION : OCI Region identifier |
| 118 | +``` |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | +### Validate the execution. |
| 124 | + |
| 125 | +- Within the `Build pipeline` click `Start manual run` |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +- Wait for all the steps to finish. |
| 130 | + |
| 131 | +- Validate the execution via build logs. |
| 132 | +- Verify the input and output file via object storage. |
| 133 | +  |
| 134 | +- Verify the run command execution status via the instance `run command` option. |
| 135 | +  |
| 136 | +- For any error during the execution you may do a trial run of `run command` against the compute instance from OCI Compute console view, validate the policies and groups and verify the build parameter |
| 137 | +- The `TIMEOUT_IN_SECONDS` value within build_spec.yaml file for the compute run command agent invoke is based on samples here, please update accordingly |
| 138 | + |
| 139 | + |
| 140 | +Read more |
| 141 | +--- |
| 142 | + |
| 143 | +- OCI DevOps service - https://docs.oracle.com/en-us/iaas/Content/devops/using/home.htm |
| 144 | +- OCI Compute run command agent - https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/runningcommands.htm |
| 145 | + |
| 146 | +Contributors |
| 147 | +=========== |
| 148 | + |
| 149 | +- Author: [Rahul M R](https://github.com/RahulMR42). |
| 150 | +- Collaborators: |
| 151 | +- Last release: December 2022 |
| 152 | + |
| 153 | +### Back to examples. |
| 154 | +---- |
| 155 | + |
| 156 | +- 🍿 [Back to OCI Devops Build sample](./../README.md) |
| 157 | +- 🏝️ [Back to OCI Devops sample](./../../README.md) |
| 158 | + |
0 commit comments