Overview
To use the Suga CLI in automated CI/CD environments, you need to authenticate without interactive login prompts. Personal Access Tokens provide a secure way to authenticate the CLI in:
- GitHub Actions
- GitLab CI
- CircleCI
- Jenkins
- BitBucket Pipelines
- Any CI/CD platform
Quick Start
Set the SUGA_ACCESS_TOKEN environment variable with your Personal Access Token:
export SUGA_ACCESS_TOKEN="your-token-here"
Once set, all Suga CLI commands will automatically authenticate using the token.
Prerequisites
Before setting up CI/CD authentication, you need to:
- Create a Personal Access Token
- Securely store the token in your CI/CD platform’s secrets management system
Never commit tokens directly to your repository. Always use your CI/CD platform’s encrypted secrets or environment variable features.
GitHub Actions
GitLab CI
CircleCI
Jenkins
GitHub Actions
Add Token to Repository Secrets
- Navigate to your GitHub repository
- Go to Settings > Secrets and variables > Actions
- Click New repository secret
- Name:
SUGA_ACCESS_TOKEN
- Value: Your Personal Access Token
- Click Add secret
Use in Workflow
name: Deploy with Suga
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Suga CLI
run: |
curl -sSL https://addsuga.com/install | sh
echo "$HOME/.suga/bin" >> $GITHUB_PATH
- name: Build and Deploy
env:
SUGA_ACCESS_TOKEN: ${{ secrets.SUGA_ACCESS_TOKEN }}
run: |
suga build
# Additional deployment commands
Documentation: GitHub Actions SecretsGitLab CI
Add Token to CI/CD Variables
- Navigate to your GitLab project
- Go to Settings > CI/CD > Variables
- Click Add variable
- Key:
SUGA_ACCESS_TOKEN
- Value: Your Personal Access Token
- Check Mask variable and Protect variable (recommended)
- Click Add variable
Use in Pipeline
stages:
- build
- deploy
variables:
SUGA_VERSION: "latest"
before_script:
- curl -sSL https://addsuga.com/install | sh
- export PATH="$HOME/.suga/bin:$PATH"
build:
stage: build
script:
- suga build
only:
- main
deploy:
stage: deploy
script:
- suga build
# Additional deployment commands
only:
- main
Documentation: GitLab CI/CD VariablesCircleCI
Add Token to Environment Variables
- Navigate to your CircleCI project
- Click Project Settings
- Go to Environment Variables
- Click Add Environment Variable
- Name:
SUGA_ACCESS_TOKEN
- Value: Your Personal Access Token
- Click Add Variable
Use in Config
version: 2.1
jobs:
build-and-deploy:
docker:
- image: cimg/base:stable
steps:
- checkout
- run:
name: Install Suga CLI
command: |
curl -sSL https://addsuga.com/install | sh
echo 'export PATH=$HOME/.suga/bin:$PATH' >> $BASH_ENV
- run:
name: Build with Suga
command: suga build
- run:
name: Deploy
command: |
# Additional deployment commands
workflows:
version: 2
build-deploy:
jobs:
- build-and-deploy:
filters:
branches:
only: main
Documentation: CircleCI Environment VariablesJenkins
Add Token to Jenkins Credentials
- Navigate to Manage Jenkins > Manage Credentials
- Select the appropriate domain
- Click Add Credentials
- Kind: Secret text
- Secret: Your Personal Access Token
- ID:
suga-access-token
- Description: “Suga Personal Access Token”
- Click OK
Use in Pipeline
pipeline {
agent any
environment {
SUGA_ACCESS_TOKEN = credentials('suga-access-token')
}
stages {
stage('Install Suga') {
steps {
sh '''
curl -sSL https://addsuga.com/install | sh
export PATH=$HOME/.suga/bin:$PATH
'''
}
}
stage('Build') {
steps {
sh '''
export PATH=$HOME/.suga/bin:$PATH
suga build
'''
}
}
stage('Deploy') {
steps {
sh '''
export PATH=$HOME/.suga/bin:$PATH
# Additional deployment commands
'''
}
}
}
}
Documentation: Jenkins Credentials
Using Tokens with Docker
When running Suga CLI in Docker containers, pass the token as an environment variable:
FROM ubuntu:22.04
# Install Suga CLI
RUN curl -sSL https://addsuga.com/install | sh
# Add Suga to PATH
ENV PATH="$HOME/.suga/bin:${PATH}"
# Token will be provided at runtime
ENV SUGA_ACCESS_TOKEN=""
WORKDIR /app
COPY . .
CMD ["suga", "build"]
Run the container:
docker run -e SUGA_ACCESS_TOKEN="your-token-here" your-image
Common CI/CD Workflows
Basic Build and Deploy
# Set token (typically done by CI platform)
export SUGA_ACCESS_TOKEN="your-token-here"
# Build infrastructure
suga build
# Deploy or additional commands
# ...
Conditional Deployment
# GitLab CI example
deploy:
stage: deploy
script:
- suga build
only:
- main
- tags
except:
- schedules
Using Tokens with Suga API
Personal Access Tokens can also be used directly with the Suga API as Bearer tokens:
curl -H "Authorization: Bearer your-token-here" \
https://app.addsuga.com/api/teams/{your_team}/platforms
// Node.js example
const response = await fetch('https://app.addsuga.com/api/teams/{your_team}/platforms', {
headers: {
'Authorization': `Bearer ${process.env.SUGA_ACCESS_TOKEN}`
}
});
# Python example
import os
import requests
headers = {
'Authorization': f'Bearer {os.environ["SUGA_ACCESS_TOKEN"]}'
}
response = requests.get('https://app.addsuga.com/api/teams/{your_team}/platforms', headers=headers)
Next Steps