How do I deploy a file to Artifactory using the command line?

Learn how do i deploy a file to artifactory using the command line? with practical examples, diagrams, and best practices. Covers command-line, gradle, artifactory development techniques with visua...

Deploying Files to Artifactory from the Command Line

Hero image for How do I deploy a file to Artifactory using the command line?

Learn how to efficiently deploy artifacts to Artifactory using various command-line tools, including cURL, Artifactory CLI, and Gradle.

Artifactory serves as a universal repository manager, centralizing all your binary artifacts. Deploying files to Artifactory from the command line is a common task for automation, CI/CD pipelines, and scripting. This article will guide you through different methods to achieve this, focusing on flexibility and common use cases.

Understanding Artifactory Deployment Basics

Before diving into specific commands, it's crucial to understand how Artifactory handles deployments. Artifactory uses a REST API for all operations, including artifact uploads. When you deploy a file, you're essentially making an HTTP PUT request to a specific URL within your Artifactory instance. This URL typically includes the repository path and the desired artifact name. Authentication is usually handled via API keys, username/password, or access tokens.

flowchart TD
    A[Local File] --> B{HTTP PUT Request}
    B --> C[Artifactory Instance]
    C --> D[Target Repository]
    D --> E[Artifact Stored]
    B -- Authentication --> C

Basic Artifactory Deployment Flow

Method 1: Using cURL for Direct Deployment

cURL is a powerful command-line tool for making HTTP requests, making it a versatile choice for deploying files to Artifactory. It's ideal for simple, direct uploads and can be easily integrated into shell scripts. You'll need your Artifactory URL, repository name, and authentication credentials (username/password or API key).

curl -u "<USERNAME>:<PASSWORD_OR_API_KEY>" \
     -X PUT "https://<ARTIFACTORY_URL>/artifactory/<REPOSITORY_KEY>/<PATH_IN_REPO>/<FILE_NAME>" \
     -T "<LOCAL_FILE_PATH>" \
     -H "X-Checksum-Sha1: <SHA1_CHECKSUM_OF_FILE>" \
     -H "X-Checksum-Md5: <MD5_CHECKSUM_OF_FILE>"

Deploying a file to Artifactory using cURL with checksums

Method 2: Leveraging the JFrog CLI

The JFrog CLI is a dedicated command-line interface for interacting with JFrog products, including Artifactory. It simplifies many operations, including artifact deployment, by abstracting away the underlying REST API calls. It also handles authentication and checksums automatically, making it a more user-friendly and robust option for complex scenarios or frequent use.

1. Install JFrog CLI

Download and install the JFrog CLI from the official JFrog website or via a package manager like Homebrew (brew install jfrog-cli).

2. Configure JFrog CLI

Run jfrog rt c to configure your Artifactory instance details, including the URL and credentials. This stores the configuration for future use.

3. Deploy the Artifact

Use the jfrog rt upload command to deploy your file. The CLI automatically calculates checksums and handles the PUT request.

# Configure Artifactory instance (run once)
jfrog rt c

# Example deployment
jfrog rt upload "<LOCAL_FILE_PATH>" "<REPOSITORY_KEY>/<PATH_IN_REPO>/<FILE_NAME>"

Deploying a file using JFrog CLI

Method 3: Deploying with Gradle

For Java-based projects, Gradle is a popular build automation tool that can also be configured to deploy artifacts to Artifactory. This method is typically used within a project's build.gradle file, allowing for automated deployment as part of the build process. The artifactory-publish plugin simplifies this integration.

plugins {
    id 'java'
    id 'maven-publish'
    id 'com.jfrog.artifactory'
}

group = 'com.example'
version = '1.0.0'

// ... other build configurations ...

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

artifactory {
    contextUrl = "https://<ARTIFACTORY_URL>/artifactory"
    publish {
        repository {
            repoKey = '<REPOSITORY_KEY>'
            username = '<USERNAME>'
            password = '<PASSWORD_OR_API_KEY>'
        }
        defaults {
            publications('mavenJava')
            publishBuildInfo = true
            publishArtifacts = true
            publishPom = true
        }
    }
    resolve {
        repository {
            repoKey = '<REPOSITORY_KEY>'
            username = '<USERNAME>'
            password = '<PASSWORD_OR_API_KEY>'
        }
    }
}

Gradle build.gradle configuration for Artifactory deployment

gradle artifactoryPublish

Command to trigger Artifactory deployment via Gradle