CloudBees action: Register an artifact deployed to an environment

2 minute read

Use this action to report artifact-related data to an environment from a CloudBees platform workflow run, for artifact traceability purposes.

This action version (v2.0) is the most recent release of the action. Previous releases are deprecated. Version 2.0 replaces multiple required inputs with a single parameter, artifact-id.

Prerequisites

Before using this action, you must first register the artifact you plan to deploy to an environment. This registration saves the artifact information to the CloudBees platform.

Do one of the following to save your artifact information to the platform:

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 1. Input details
Input name Data type Required? Description

artifact-id

String

Yes

The unique identifier of the artifact ID output from the CloudBees platform.

target-environment

String

Required if no job-level environment is specified.

The environment where the deployment is located. The target-environment value overrides the jobs.<job_id>.environment value.

labels

String

No

A comma-separated list of artifact labels.

Usage examples

Basic example

The following is a basic example of using the action:

jobs: register_artifact_version_to_my_env: environment: my_env steps: - name: Register deployed artifact uses: cloudbees-io/register-deployed-artifact@v2 with: artifact-id: 1234abcd-56ef-ab78-9012-cdef78903456

Using optional inputs

The following example specifies artifact labels:

jobs: register_artifact_version_to_qa_env: environment: qa_env steps: - name: Register deployed artifact with labels uses: cloudbees-io/register-deployed-artifact@v2 with: artifact-id: 1234abcd-56ef-ab78-9012-cdef78903456 labels: label1,label2

Full workflow example with Kaniko

This example publishes an image with Kaniko, and then reports the data to the platform.

apiVersion: automation.cloudbees.io/v1alpha1 kind: workflow name: Deployment workflow on: workflow_dispatch: jobs: build: outputs: artifact-id: ${{ fromJSON(steps.push-image.outputs.artifact-ids)[ format('index.docker.io/{0}/my-sample-go-app:{1}', vars.DOCKER_USERNAME, cloudbees.version) ] }} steps: - uses: docker://alpine/git:latest run: | git config --global --add safe.directory /cloudbees/workspace - name: checkout uses: cloudbees-io/checkout@v1 - name: Build Go app uses: docker://golang:1.20 kind: build run: | go build -v ./... - name: Set up Docker Hub registry uses: cloudbees-io/configure-oci-credentials@v1 kind: deploy with: registry: index.docker.io username: ${{ vars.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Push image to OCI registry id: push-image uses: cloudbees-io/kaniko@v1 with: destination: index.docker.io/${{ vars.DOCKER_USERNAME }}/my-sample-go-app:${{cloudbees.version}} deploy: needs: build steps: - name: Register deployed artifact uses: cloudbees-io/register-deployed-artifact@v2 with: artifact-id: ${{ needs.build.outputs.artifact-id }} target-environment: dev