Python Builds with Artifactory - Declarative Pipeline Syntax

JFrog Integrations Documentation

Content Type


We recommend using the integration with the JFrog Jenkins Plugin, rather than using the following DSL.

Python builds can resolve dependencies, deploy artifacts and publish build-info to Artifactory. To run Python builds with Artifactory start by following these steps, to make sure your Jenkins agent is ready:

  1. Make sure Python is installed on the build agent and that the python command is in the PATH.

  2. Install pip. You can use the Pip Documentation and also Installing packages using pip and virtual environments.

  3. Make sure wheel and setuptools are installed. You can use the Installing Packages Documentation.

  4. Validate that the build agent is ready by running the following commands from the terminal:

Output Python version:
> python --version
Output pip version:
> pip --version
Verify wheel is installed:
> wheel -h
Verify setuptools is installed:
> pip show setuptools
Verify that virtual-environment is activated:

To run Python builds from your Pipeline script, you first need to create an Artifactory server instance, as described in the Creating an Artifactory Server Instance section.

The next step is to define an rtPipResolver, which defines the dependencies resolution details. Here's an example:

rtPipResolver (
    id: "resolver-unique-id",
    serverId: "Artifactory-1",
    repo: "pip-virtual"

As you can see in the example above, the resolver should have a unique ID, so that it can be referenced later in the script, In addition, it includes an Artifactory server ID and the name of the repository.

Now we can use the rtPipInstall closure, to resolve the pip dependencies. Notice that the closure references the resolver we defined above.

rtPipInstall (
    resolverId: "resolver-unique-id",
    args: "-r python-example/requirements.txt",
    envActivation: virtual_env_activation,
        // Jenkins spawns a new java process during this step's execution.
        // You have the option of passing any java args to this new process.
        javaArgs: '-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005'
    // If the build name and build number are not set here, the current job name and number will be used:
    buildName: 'my-build-name',
    buildNumber: '17',
    // Optional - Only if this build is associated with a project in Artifactory, set the project key as follows.
    project: 'my-project-key'

Notice the envActivation property in the example above. Is is an optional property. Since it is mostly recommended to run pip commands inside a virtual environment, to achieve isolation for the pip build. To follow this recommendation, you have the option of using the envActivation by sending a shell script as its value, for setting up the virtual env.

In most cases, your build also produces artifacts. The artifacts produced can be deployed to Artifactory using the rtUpload closure, as described in the Uploading and Downloading Files section in this article.

The last thing you might want to do, is to publish the build-info for this build. See the Publishing Build Info to Artifactory section for how to do it.

More about build-info: You also have the option of customising the build-info module names. You do this by adding the module property to the rtPipInstall closure as follows:

rtPipInstall (
    resolverId: "resolver-unique-id",
    args: "-r python-example/requirements.txt",
    envActivation: virtual_env_activation,
        module: 'my-custom-build-info-module-name'