Visual Builder Studio includes free git repositories for Oracle Cloud customers that can host any source code. For developers building Visual Builder apps or Fusion Apps extensions the VB Studio git repository is the only supported git solution, and it is tightly integrated with the VB Studio's workspace feature providing excellent and seamless version management experience. But some organizations may also want to push code changes to an external Git host such as GitLab, GitHub or others. For example, if a company has an additional Git repository that hosts all the code your company develops.
While you can easily import or mirror an external Git repository into VB Studio to allow you automate CI/CD for that code, these external repositories are in "read-only" mode.
In the following example, we show how to create a build job that will automate syncing internal VB Studio Git repo with an external one.
Quick Links
Sync a Visual Builder Application
Prerequisites
- For this post it is expected that you have enough of an understanding of Git to be able to handle any issues that may come from Git.
- Have both a VBS Git repo and an external repo
For the below examples, I started with a repo on GitHub and cloned it into VBS using the "Create Repository" feature in VBS. If you have existing repositories, you will need to make sure they are synced up before running the examples. - You will need to configure the external repo security so you can push to it using HTTPS and/or SSH.
Make a build job
- In VBS, switch to "Builds" and click the "Create Job" button
- Enter a Name, chose a Template and click "Create"
- Open the "Git" tab in the Job Configuration and click "Add Git"
- Select the VBS Git repo that you'd like to push externally
Optional:- If you would like, you can select "Automatically perform build on SCM commit. This will automate the job to execute whenever there's a change to the selected branch
- You could also configure the job to sync from a specific branch such as "Sync-to-XRepo"
Configure a Build Step
In order to work with an external or "remote" repo you need to add the remote to the local (inside the build executor) git repo using the "git remote add" command.
You can find more information in the Git Docs.
You can push using either HTTPS or SSH.
HTTPS
Prerequisite:
You will need a user and password in your external host with permissions to push to the repository. I highly recommend creating an access token specifically for this build job. If you are not sure how to create one, you'll need to follow the instructions from your external site.
The password / token should be stored as a secure password parameter in the job.
- Switch to the "Parameters" tab, click on "Add Parameter" and select "Password/Private Key Parameter
- Enter a descriptive Name for the Parameter then enter the Password/Token in the Default Value field
Copy the name, you'll need it in the next step - Switch to the "Steps" tab, click on "Add Step", "Common Build Tools", "Unix Shell"
- Enter the following script using the HTTPS URL from your external repository. In my example, I'm connecting to GitHub.
git remote add "GitHub" https://OsBlaineOra:${GitHubPersonalAccessToken}@github.com/OsBlaineOra/VBS-Sync.git git push GitHub mainReplace the text in my examples with the values for your remote repository.
Replace the password part of the URL with the Parameter you created in the previous step, ${GitHubPersonalAccessToken} - Click Save
- Skip to Run the Build Job
SSH
- You will need an RSA key for this step. If you have issues with the key not working, make sure it is a "pem" key. The following command will create a new pem key called ~/.ssh/git_sync_key
ssh-keygen -t rsa -N "" -b 2048 -C "cicd_key" -m pem -f ~/.ssh/git_sync_key
- Add the public key to your remote git repository. If you need help with this step read the docs provided by your remote.
- You will need the public key of your remote server. You can use the following command to retrieve the public key. (For sites other than GitHub, replace "gitub.com" with the site URL.)
ssh-keyscan -t rsa github.com
- Open the "Before Build" tab, click on "Add Before Build Action and select "SSH Configuration"
- Copy your private key and paste it into the "Private Key" field
- Copy the public key for your remote repository from above and paste it into the "Host Key" field
Below you can see the value for GitHub. - Check the box "Setup files in ~/.ssh for command-line ssh tools"
Bonus: This configuration can be used for any SSH commands you want to run in the Shell step.
- Switch to the "Steps" tab, click on "Add Step", "Common Build Tools", "Unix Shell"
- Enter the following script using the SSH URL from your external repository. In my example, I'm connecting to GitHub.
git remote add "GitHub" git@github.com:OsBlaineOra/VBS-Sync.git git push GitHub main
Replace the text in my examples with the values for your remote repository. - Click Save
Run the Build Job
Click "Build Now" to run the build job and push a copy of your VBS repository to your remote
- If you are using the HTTPS method, you will get a pop up with an option to use a different password than the default. Click "Build Now"
The code from VBS should now be pushed into your remote repository.
Sync a Visual Builder Application
Now that you know how to use Git in your build, you can use it to push a VB app to your remote repository.
Prerequisite: For the following example, I created a new empty repository on GitHub
- Open the build job created above
- Open the "Git" tab and select the VBS Git repository for your VB Application
- Open the "Steps" tab and modify the Git shell step
*Note: You will want to modify these commands based on how you want to manage your git process- Change the remote repository to the new empty repo
git remote add "VB_GitHub" git@github.com:OsBlaineOra/VB_App_Sync.git
- Push main to your new repository
git push VB_GitHub main
git remote add "VB_GitHub" git@github.com:OsBlaineOra/VB_App_Sync.git git push VB_GitHub main
- Change the remote repository to the new empty repo
- Click "Save"
- Click on "Builds", open the "Pipeline" tab and select the pipeline created for your VB application
- Click "Configure"
- Right click on the Deploy job, select Add, "Add New On Success Jobs"
- Select the Build Job created above and click "Save"
- Click "Save" for the Pipeline
- Run the Pipeline
GitHub after the Pipeline was run
Now whenever you publish changes to your VB application, the pipeline will run and push the changes to your remote repository automatically.
It's All "Just" Git
I try to not use "just" since it can come across as oversimplification, but once you have the basic example setup, it's all just Git commands.
This post uses the most basic git commands. You can modify the shell step to execute any git commands you'd like.
For example, I like to run "git status" before other git commands.
Or, maybe you'd rather not push to the remote main branch, you could create a pull request instead.
Disclaimer: More advanced git commands and the errors that may or may not come with them are out of scope for this post.
You can find help for git commands in the Git Docs.
If you'd like to push to multiple repositories, go back to the "git remote add" step add as many as you'd like then enter the git commands you'd like to run.
When you're working with VBS Build jobs, you don't have to have a "pre-configured" step. If there's something you'd like to do and there's not a step option, set it up in a Shell step.
