Skip to main content
Version: Release Next

Python 3 Script (Container) Task

The Python 3 Script (Container) task runs a Python 3 script in a container through the Release Runner. Scripts have direct access to the Release API and to current-context helpers, so you can read and update releases, phases, tasks, and variables without writing boilerplate.

note

In the release flow editor, Container tasks have a blue border.

Prerequisites

  • A configured Digital.ai Release Runner to run container tasks.
  • A run-as user on the release or template. Every API call and helper runs as this user, so API calls fail if it is not set. Set the Run automated tasks as user property. For more information, see Create a Jython Script task.

Install the Plugin

To install the Python3 Script (Container) plugin in Digital.ai Release:

  1. Launch Release.
  2. Click the Settings icon located on the right side of the top navigation bar.
  3. From the dropdown menu, select Manage Plugins.
  4. In the search bar, type Python3 Script (Container).
  5. When the plugin appears in the search results, click Install Now.

Once installed, the Python3 Script (Container) plugin is available for use in your release flows.

Plugin Installation Screenshot

Add a Python 3 Script Task

  1. In the release flow tab of a template, add a task of type Script > Python3 Script (Container).
  2. Click the added task to open it.
  3. In the Capabilities field, enter a value that matches the capability set for your Runner. This will help you to route jobs to that particular Runner.
  4. In the Script field, type or paste the Python 3 script that you want to execute.

The following script calculates subtotal, shipping, and total order cost:

subtotal = 100 * 3
shipping = 25
result = subtotal
result_2 = shipping
result_3 = subtotal + shipping

All three values (result, result_2, result_3) are available as output properties in the task result.

Python3 script (Container) Python3 script (Container) Output

Runtime and Packages

The container image includes the Python 3 standard library and transitive dependencies of the bundled Python SDK, such as requests and pydantic. Additional packages not in the image (such as numpy or pandas) are not importable unless added to the container image.

Predefined Objects and Methods

The Python 3 Script task provides access to predefined API objects and helper methods. These are available directly in your script without importing:

Object / MethodPurpose
releaseApiAccess Release API methods (create, retrieve, update releases)
phaseApiAccess Phase API methods
taskApiAccess Task API methods
folderApiAccess Folder API methods
templateApiAccess Template API methods
configurationApiAccess shared configurations and global variables
variableApiAccess variable operations
getCurrentRelease()Get the current release context
getCurrentPhase()Get the current phase context
getCurrentTask()Get the current task context
getCurrentFolder()Get the current folder context
getReleaseVariable(name)Get a release variable by name
setReleaseVariable(name, value)Set a release variable
getGlobalVariable(name)Get a global variable
setGlobalVariable(name, value)Set a global variable

Example script accessing predefined objects:

from com.xebialabs.xlrelease.domain.release import Release

# Get current release and add a comment
release = getCurrentRelease()
result = f"Working on release: {release.title}"

# Retrieve a release variable
build_number = getReleaseVariable("buildNumber")
result_2 = f"Build: {build_number}"

# Update a release variable
setReleaseVariable("deployTarget", "production")
result_3 = "Deployment target set to production"

Sample Scripts

This example creates a release from a template, adds a task, and starts the release:

from datetime import datetime, timedelta, timezone
from com.xebialabs.xlrelease.domain.forms import CreateRelease
from com.xebialabs.xlrelease.domain.release import Release
from com.xebialabs.xlrelease.domain.task import Task

release_title = "Automated Release (sample)"
phase_title = "Build"
task_title = "Run Jython"

# Create a template with a start date
start = datetime.now(timezone.utc)
template = templateApi.createTemplate(
Release(
title=f"{release_title} - Template",
scheduledStartDate=start,
dueDate=start + timedelta(days=7),
)
)
print(f"Template created -> id={template.id}")

# Create a release from the template
release = templateApi.create(
template.id,
CreateRelease(releaseTitle=release_title),
)
print(f"Release created -> id={release.id}, status={release.status}")

# Rename the default phase
created = releaseApi.getRelease(release.id)
phase = created.phases[0]
phase.title = phase_title
phase = phaseApi.updatePhase(phase.id, phase)
print(f"Phase renamed -> title='{phase.title}'")

# Add a Jython script task
jython_script = "print 'Hello from Jython!'"
task = taskApi.addTask(
phase.id,
Task(title=task_title, type="xlrelease.ScriptTask", script=jython_script),
)
print(f"Task added -> id={task.id}")

# Start the release
started = releaseApi.start(release.id)
print(f"Release started -> status={started.status}")

# Return results
result = started.id
result_2 = task.id
result_3 = f"status={started.status}"

Migrating from Jython

To move existing Jython Script tasks to this task, see Migrate Jython Script to Python 3 Script (Container).