Integrations

Integrating Semaphore CI

Semaphore is a hosted continuous integration and deployment service used for testing and deploying software projects hosted on GitHub and BitBucket.

You can create your workflow and pipelines by writing YAML configuration files and committing them along with your source code, or using the intuitive Visual Builder that Semaphore includes.

No Code Uploading

The Cloudsmith CLI gives you full control when connecting to any CI/CD process, allowing you to upload any of our support formats or query your repositories. Just configure your API Key, install the CLI, and you'll be all set.

In the following examples:

IdentifierDescription
WORKSPACEYour Cloudsmith Workspace slug
REPOSITORYYour Cloudsmith Repository name (also called "slug")
FORMATThe format of the package, for example, "deb", "maven", or "npm"
PACKAGE_FILEThe filename of the package

API Key Configuration

You need to add your Cloudsmith API Key in order to authenticate to Cloudsmith for pushing packages. We recommend storing your Cloudsmith API Key as a secret in Semaphore. Secrets in Semaphore are organization-level objects that can contain environment variables or files which you can then access in your build jobs.

Alternatively, you can authenticate without a stored API key by using OpenID Connect (OIDC). Set the CLOUDSMITH_OIDC_TOKEN, CLOUDSMITH_ORG, and CLOUDSMITH_SERVICE_SLUG environment variables and the CLI automatically exchanges the OIDC token for a short-lived Cloudsmith token. See OpenID Connect for provider setup.

You can add a secret using the Semaphore CLI or the UI:

Push Package Example

To Push a package to Cloudsmith from a Semaphore CI Pipeline, you just need to add your Cloudsmith API Key secret and the cloudsmith push CLI command to one of the blocks in your pipeline

For example:

yaml
  - name: Push Package
    task:
      secrets:
        - name: Cloudsmith-API
      jobs:
        - name: Push
          commands:
            - cache restore package
            - cloudsmith push FORMAT WORKSPACE/REPOSITORY PACKAGE_FILE
      prologue:
        commands:
          - install_output="$(curl -fsSL https://install.cloudsmith.com/raw/versions/latest/cli.sh | sh -s -- --version 1.20.1)"
          - bin_dir="$(printf '%s\n' "$install_output" | sed -n 's/^bin_dir=//p')"
          - export PATH="$bin_dir:$PATH"

Note

The push command varies with the package format. For example, pushing a Debian package looks like: cloudsmith push deb WORKSPACE/REPOSITORY/ubuntu/xenial foo-1.0.deb. See the Cloudsmith CLI for full details of the push command for other formats.

In the above example, we use the commands executed during the block prologue to install the standalone Cloudsmith CLI with the install script, so that the cloudsmith push command is available. The install script prints the installation result as key=value lines; the prologue parses bin_dir from that output and adds it to PATH.

In addition, we also use the cache restore command to retrieve the package file that was built in a previous block. Please see the Semaphore Cache documentation for more detail on storing and retrieving artifacts using the Semaphore cache

Note

Where supported, you can also use native publishing commands like docker push or npm publish instead of using the Cloudsmith CLI, provided you have installed the necessary tooling as part of your pipeline block setup.