Build and Push to JFrog Docker registries
Use a CI pipeline to build and push an image to a JFrog Docker registry.
This topic explains how to use the Build and Push an image to Docker Registry step to build and push an image to JFrog Artifactory Docker registries.
For JFrog non-Docker registries, you can use a script in a Run step to build the artifact, and then use the Upload Artifacts to JFrog step to upload the artifact.
You need:
Access to a JFrog Artifactory instance with a Docker registry.
A CI pipeline with a Build stage.
A Harness Docker connector configured to your JFrog instance.
Build and push to JFrog Docker registries
In your pipeline's Build stage, add a Build and Push an image to Docker Registry step and configure the settings for JFrog.
Here is a YAML example of a Build and Push an image to Docker Registry step configured for JFrog:
- step:
type: BuildAndPushDockerRegistry
name: Build and push to JFrog Docker
identifier: Build_and_push_to_JFrog_Docker
spec:
connectorRef: YOUR_DOCKER_CONNECTOR_ID
repo: domain.jfrog.io/REPO/IMAGE
tags:
- <+pipeline.sequenceId>When you run a pipeline, you can observe the step logs on the build details page. If the Build and Push step succeeds, you can find the uploaded image in JFrog.
Using Local Tar Output
In scenarios where pushing a Docker image to a registry is not feasible, you can generate a local tarball of the built image instead. This approach is particularly useful for situations like local testing or when registry access is unavailable during the build process.
Once the tarball is generated, you can use a Security Testing Orchestration (STO) step, such as Aqua Trivy, to scan the image for vulnerabilities. This workflow ensures that images are built and scanned effectively, even without access to a remote registry.
Here’s a sample partial pipeline that demonstrates how build the image, generate the tarball, and push it to the registry:
The PLUGIN_NO_PUSH: "true" environment variable prevents the image from being pushed to the registry.Here’s a sample partial pipeline that demonstrates how build the image, generate the tarball, but skip pushing it to the registry:
Step settings
These sections explain how to configure the Build and Push an image to Docker Registry step settings for JFrog. Depending on the build infrastructure, some settings might be unavailable or optional. Settings specific to containers, such as Set Container Resources, are not applicable when using a VM or Harness Cloud build infrastructure.
Name
Enter a name summarizing the step's purpose. Harness automatically assigns an Id (Entity Identifier) based on the Name. You can change the Id until the step is saved. Once save, the Id can't be changed.
Docker Connector
Specify a Harness Docker Registry connector configured for JFrog.
To create this connector:
Go to Connectors in your Harness project, organization, or account resources, and select New Connector.
Select Docker Registry under Artifact Repositories.
Enter a Name for the connector. The Description and Tags are optional.
For Provider Type, Select Other.
In Docker Registry URL, enter your JFrog URL, such as
https://mycompany.jfrog.io.In the Authentication settings, you must use Username and Password authentication.
Username: Enter your JFrog username.
Password: Select or create a Harness text secret containing the password corresponding with the Username.
Complete any other settings and save the connector. For information all Docker Registry connector settings, go to the Docker connector settings reference.
Docker Repository
The repo where you want to store the image and the image name, for example, mycompany.jfrog.io/REPO_NAME/IMAGE_NAME.
Tags
Add Docker build tags. This is equivalent to the -t flag.
Add each tag separately.

Optimize
With Kubernetes cluster build infrastructures, select this option to enable --snapshotMode=redo. This setting causes file metadata to be considered when creating snapshots, and it can reduce the time it takes to create snapshots. For more information, go to the Kaniko documentation for the snapshotMode flag.
For information about setting other kaniko runtime flags, go to Environment variables.
Dockerfile
The name of the Dockerfile. If you don't provide a name, Harness assumes that the Dockerfile is in the root folder of the codebase.
Context
Enter a path to a directory containing files that make up the build's context. When the pipeline runs, the build process can refer to any files found in the context. For example, a Dockerfile can use a COPY instruction to reference a file in the context.
Labels
Specify Docker object labels to add metadata to the Docker image.
Build Arguments
The Docker build-time variables. This is equivalent to the --build-arg flag.

Target
The Docker target build stage, equivalent to the --target flag, such as build-env.
Docker layer caching and Remote cache image
There are two ways in which you can leverage Docker Layer Caching: Enable Docker layer caching ('caching' property) or Remote cache image ('remoteCacheRepo' property). Refer to Enable Docker layer caching for your build to learn more.
Environment Variables (plugin runtime flags)
Build and Push steps use plugins to complete build and push operations. With Kubernetes cluster build infrastructures, these steps use Chainguard's maintained Kaniko fork. With other build infrastructures, these steps use drone-docker.
These plugins have a number of additional runtime flags that you might need for certain use cases. For information about the flags, go to the Kaniko plugin documentation and the drone-docker plugin documentation.
In Environment Variables for your step, add the environment variable PLUGIN_BUILDX_OPTIONS to pass any supported options to the buildx command used by the build and push steps.
How you configure plugin runtime flags depends on your build infrastructure.
Run as User
With Kubernetes cluster build infrastructures, you can specify the user ID to use to run all processes in the pod if running in containers. For more information, go to Set the security context for a pod.
This step requires root access. You can use the Run as User setting if your build runs as non-root (runAsNonRoot: true), and you can run the Build and Push step as root. To do this, set Run as User to 0 to use the root user for this individual step only.
If your security policy doesn't allow running as root, go to Build and push with non-root users.
Set Container Resources
Set maximum resource limits for the resources used by the container at runtime:
Limit Memory: The maximum memory that the container can use. You can express memory as a plain integer or as a fixed-point number using the suffixes
GorM. You can also use the power-of-two equivalentsGiandMi. The default is500Mi.Limit CPU: The maximum number of cores that the container can use. CPU limits are measured in CPU units. Fractional requests are allowed; for example, you can specify one hundred millicpu as
0.1or100m. The default is400m. For more information, go to Resource units in Kubernetes.
Timeout
Set the timeout limit for the step. Once the timeout limit is reached, the step fails and pipeline execution continues. To set skip conditions or failure handling for steps, go to:
Conditions, looping, and failure strategies
You can find the following settings on the Advanced tab in the step settings pane:
Conditional Execution: Set conditions to determine when/if the step should run.
Failure Strategy: Control what happens to your pipeline when a step fails.
Use looping strategies: Define a matrix, repeat, or parallelism strategy for an individual step.
Publish Build metadata to a Docker image in JFrog Docker Registry
Use the Harness plugin to publish build metadata to a Docker image in the JFrog Docker Registry. It's useful for tracking and managing Docker builds in Artifactory, ensuring that all relevant build information is stored alongside your images.
For example:
Plugin specification
connectorRef: Harness Connector for the container registry where the plugin image is located.
image: The Docker image containing the plugin to publish build info. For this example, it's
plugins/artifactory-publish-docker-buildinfo.
Settings:
access_token: The access token for authenticating with Artifactory. In the example above it's retrieved from Harness secrets manager.
url: The URL of the Artifactory instance where the build info will be published.
build_name: The name of the build, typically set to the pipeline name.
build_number: The build number, typically set to the pipeline execution ID.
build_url: The URL to the pipeline execution in Harness, allowing quick access to the build details.
docker_image: The Docker image for which to attach the build metadata, including its tag.
You can securely perform SSH-based operations in your Docker builds — such as cloning private Git repositories — by mounting an SSH key into the build using Docker BuildKit’s --ssh feature. The SSH key is mounted only during the build process and is never baked into the final image.
Below is a full working Harness CI pipeline example:
Key points:
--mount=type=ssh,id=sshkeyin the Dockerfile matches--ssh=sshkey=/harness/id_ed25519inPLUGIN_BUILDX_OPTIONS.The SSH key comes from the Harness Secrets Manager, as shown in the SSH Key Prep step above where a file secret is used to create
/harness/id_ed25519. It is mounted only during the build.In this example, cloneCodebase is set to
falsebecause the Dockerfile is created in the pipeline itself. In your own pipelines, set this totrueif your Dockerfile (or other build context files) is stored in a repository that Harness needs to clone before the build.
Troubleshoot Build and Push steps
Go to the CI Knowledge Base for questions and issues related to building and pushing images, such as:
Last updated
Was this helpful?


