Technical Articles

Tech Articles from your friends at Oracle and the developer community.

Creating Code Repositories in OCI DevOps service using the OCI CLI

Oracle Cloud Infrastructure DevOps service offers a range of capabilities to developers. One of these is Code Repositories, which allows you to use Git version control to maintain your source code, with as many repositories as you need for your operations.

The first thing you need to do to start using Code Repositories is to create a Project to host your new repository. If you already have a project, you’ll just need its OCID and you can skip to the next section.

  1. Navigate to cloud.oracle.com
  2. Click the “hamburger” icon in the upper left.
  3. Type “projects” in the search field, then click “Projects DevOps” on the right.

    Screenshot of: Type "projects" in the search field, then click "Projects DevOps" on the right.

  4. Click the “Choose a compartment” field and select your compartment.

    Screenshot of: Click the "Choose a compartment" field and select your compartment.

  5. Click “Create devops project”

    Screenshot of: Click "Create devops project"

  6. Type a name for your project, in this case I’m using RepositoryDemo
  7. Click “Select topic”
  8. You need to assign a topic to the project. If you don’t have any topics available, you’ll need to add at least one to your instance.

    Screenshot of: Click "Select topic"

    Select topic

  9. Click “Create devops project”

    Screenshot of: Click "Create devops project"

Take note of the OCID of the new project, you’ll need it in the next steps. You can just click on “Copy” next to the OCID label to copy the (rather long) string to your clipboard automatically.

Creating the repository

Once you have a Project created, you can use the oci command line tool to generate a repo. You can do this either in the Cloud Shell, or in you local Terminal if you have oci installed.

To create a repository, we’ll use oci create.

oci devops repository create --name "NAME-OF-PROJECT" --project-id "OCID_FOR_PROJECT" --repository-type HOSTED --query 'data.["http-url","ssh-url"]'

--name is the name of the project for which you’re creating the new repo. --project-id needs to be the OCID for the project, which you can copy from the project overview in the console. The --repository-type should be HOSTED to create a repository you can remotely access with SSH. Adding the --query to the end will return the HTTP and SSH urls for the new repository.

You can also retrive the SSH URL for all repositories using the list command:

oci devops repository list --project-id "OCID_FOR_PROJECT"

You’ll see an entry for ssh-url in the response.

Alternatively, you can grab the new ID for your repo at the time of creation and then use repository get to retrive the urls:

repoId=$(oci devops repository create --name "NAME-OF-PROJECT" --project-id OCID_FOR_PROJECT --repository-type HOSTED --query 'data.id' | sed s'/[\[",]//g')

Then use repository get:

oci devops repository get --repository-id $repoId --query 'data.["http-url","ssh-url"]'

Using the repository

  1. First, create a new directory on your local machine where you want to store your code. This can be done by opening the command prompt or terminal and navigating to the desired location, then using the command mkdir [directory name].
  2. Next, initialize the directory as a Git repository by using the command git init within the newly created directory.
  3. Connect your local repository to a remote repository by using the command git remote add origin [ssh URL from above]. This allows you to push and pull code from the remote repository to your local machine.
  4. Create a new file in the directory, for example, example.sql and add some sample code to it.
  5. Use the command git add [file name] to add the new file to the repository.
  6. Use the command git commit -m [commit message] to commit the changes to the repository.
  7. Finally, use the command git push origin master to push the changes to the remote repository.

Your Oracle code repository is now set up and ready to use. You can continue to add and commit code changes as needed, and use the git pull command to retrieve updates from the remote repository.

Latest content

Explore and discover our latest tutorials

Serverless functions

Serverless functions are part of an evolution in cloud computing that has helped free organizations from many of the constraints of managing infrastructure and resources. 

What is a blockchain?

In broad terms, a blockchain is an immutable transaction ledger, maintained within a distributed peer-to-peer (p2p) network of nodes. In essence, blockchains serve as a decentralized way to store information.

OCI CLI

The CLI is a small-footprint tool that you can use on its own or with the Console to complete Oracle Cloud Infrastructure tasks. The CLI provides the same core functionality as the Console, plus additional commands.