CI/CD
Configure your CI/CD platform to use diversion
Generate an API Token
Navigate to the tokens page
Hover over your avatar, wait for the dropdown menu and select API Tokens.
Generate a new token
Hit the Generate a new API token button.
Provide your login credentials, if prompted. You will be redirected to see your new API Token.
Use the Copy token button to copy the token and store it in a secure place.
Set up your CI/CD platform
Store the Diversion client ID
Store the API Token securely
If your platform doesn’t support secure secrets handling, you can use external secret handling tools:
- Hashicorp Vault (has a plugin for TeamCity)
- Akeyless (has a plugin for TeamCity)
- Azure Key Vault (has a plugin for TeamCity)
- Google Secret Manager
- AWS Secrets Manager
Create a build step in your CI/CD workflow
Install the Diversion client, authenticate it and clone your repo
In your CI/CD step editor or yml
file, create a new Shell build step with the following content:
$API_TOKEN
with the appropriate way to reference your secret from the secure storage.
Consult your platform’s docs and the secure storage docs.my-repository
with the name of your repository.dv status
will block until all the files are downloaded. This is important before starting to work.
It will also output the workspace ID if you want to reuse it for the next runs or view it in the web app.-new-workspace
will create a new workspace for each run of the CI/CD workflow. Passing a workspace argument here
is important, or else the clone command will prompt for user input and block. See dv help clone
for details.Add the rest of your CI/CD workflow
That’s it. You’re all set to use your Diversion repo in your CI/CD workflow. You can also use any CLI commands you would
use with dv
when running locally.
A Jenkins example
Be sure to replace the placeholders with your actual values. Also note that this syntax is for a Windows node, so you may need to adjust it for your specific setup.
pipeline
{
agent
{
any
}
environment
{
USER_POOL_CLIENT_ID = "j084768v4hd6j1pf8df4h4c47"
DV_WORKSPACE = "<Workspace ID>" //Found in Diversion using 'dv workspace' command
DV_REPO = "<Diversion Repository Name>" //Your repository name
}
stages
{
stage('Sync Repository')
{
steps
{
script
{
// Checking if Diversion CLI is installed and installing from API if not
if (!fileExists("${USERPROFILE}\\.diversion\\bin\\dv.exe"))
{
echo "Diversion not installed at ${USERPROFILE}\\.diversion\\bin\\dv.exe, installing..."
powershell 'iwr https://get.diversion.dev/win-ci | iex'
}
//Authenticating Diversion CLI
withCredentials([string(credentialsId: '<Jenkins Credential ID>', variable: 'API_TOKEN')]) //Insert your credential ID found in Jenkins Credentials
{
echo "Diversion CLI installed, authenticating..."
bat "dv authenticate %API_TOKEN%"
}
//Cloning repository if it is not already cloned
if (!fileExists("${WORKSPACE}\\${DV_REPO}\\.diversion"))
{
echo "Diversion authenticated, empty folder found, cloning repository..."
bat "dv clone ${DV_REPO} -workspace ${DV_WORKSPACE}"
}
//Pulling latest changes if repository is already cloned
else
{
echo "Diversion repository already cloned, pulling latest changes..."
bat "cd ${WORKSPACE}\\${DV_REPO} && dv update"
}
//Displaying status of repository until tasks complete (so we do not start more tasks until it is done)
bat "cd ${WORKSPACE}\\${DV_REPO} && dv status"
}
}
}
}
}