ARTIFACTORY: How to use an Access Token environment variable with the JFrog CLI

AuthorFullName__c
Patrick Russell
articleNumber
000005891
FirstPublishedDate
2023-10-16T07:14:02Z
lastModifiedDate
2025-05-21

ARTIFACTORY: How to use an Access Token environment variable with the JFrog CLI

User-added image

For the security-conscious, using an Access Token as an Environment Variable is a very secure way to authenticate against Artifactory. This does mean some extra steps have to be taken to use tools like the JFrog CLI. In particular, the "config" step needs to be done in just the right way to use this token.

In this article we'll be using an NPM project as an example, but the "jf config" step can be applied more broadly to other build types.

Step 1] Download and Configure the CLI

You'll need to download and install the V2 version of the JFrog CLI from here to use it in a build:

https://jfrog.com/getcli/

There are various ways to install the tool, select the method you prefer.

Next, configure the tool to connect to JFrog Artifactory. If this is using an environment variable in an automation script, this syntax should be used by the script:
 

#export ACCESS_TOKEN=ey[...Access-Token...]
# Interactive = False means you will skip the setup wizard

jf config add --access-token=$ACCESS_TOKEN --url=http://localhost:8082 --interactive=false artifactory-example


To confirm things are working, verify the config is loaded with "jf config show" and then run a "jf rt ping" to ping the Artifactory:

jf config show


#Expected Output:

User-added image
 

 jf rt ping


#Expected output:
OK

Step 2] Use the CLI in your project

The precise next step does depend on how the project has been configured. For this example, we will navigate to an existing NPM project (You can create one by running "jf npm init").

Once you're in your project folder, configure the JF NPM client for the first time:
 

jf npm-config

Resolve dependencies from Artifactory? (y/n) [y]? y
Set Artifactory server ID [artifactory-example]: artifactory-example

#Note: You can use a Virtual here for both Resolve and Deploy fields
Set repository for dependencies resolution (press Tab for options): npm-remote 
Deploy project artifacts to Artifactory? (y/n) [y]? y
Set Artifactory server ID [artifactory-example]: artifactory-example
Set repository for artifacts deployment (press Tab for options): npm-local

11:45:30 [🔵Info] npm build config successfully created.


That should do the trick! You're now ready to use the secure environment variable with the JFrog CLI for this build:


User-added image
User-added image
User-added image

2023-10-05T18:47:27.805Z [dfa9b315beed614 ] [ACCEPTED DEPLOY] npm-local:test-package/-/test-package-1.11.0.tgz  for client : npm-token-test / 127.0.0.1 [token]