PythonBuildStep

A Python build step

Example. Adds a simple Python build step which runs a Python script with parameter located in the working directory with automatically detected Python 3 on agent and without any environment.

buildType {
// Other Build Type settings ...
steps {
// Other Build Steps ...
        python {
command = file {
filename = "user_script.py"
scriptArguments = "%user.param%"
}
}




}
}




Example. Runs Python tests with arguments with coverage via pytest with custom Python executable path, environment and working directory which is different from the checkout directory. This build step will be executed only if running build status is successful.

buildType {
// Other Build Type settings ...
steps {
// Other Build Steps ...
        python {
name = "Run Python tests"
executionMode = BuildStep.ExecutionMode.RUN_ON_SUCCESS
workingDir = "python-tests"
pythonVersion = customPython {
executable = "/usr/bin/python3"
}

// Environment tools are available: venv, virtualenv, pipenv, poetry
environment = venv {
requirementsFile = "requirements-tests.txt"
}

// Commands are available: file, module, script, unittest, pytest, flake8, pylint
command = pytest {
isCoverageEnabled = true
scriptArguments = "-m slow"
}
}

















}
}




Example. Runs Python script with parameter given directly in the build step. Environment will be created with specified dependencies.

buildType {
// Other Build Type settings ...
steps {
// Other Build Steps ...
        python {
name = "Try Python request"

environment = venv {
// If requirementsFile is not set it will be "requirements.txt" by default
requirementsFile = ""
// Specify extra pip run arguments, e.g. dependencies
pipArgs = "requests"
}

command = script {
content = """
import requests
r = requests.get('https://httpbin.org/basic-auth/user/pass', auth=('user', '%user.password%'))
print(r.status_code)
""".trimIndent()
}
}
















}
}




See also

Constructors

Link copied to clipboard
constructor(init: PythonBuildStep.() -> Unit)
constructor()

Types

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Docker image platforms

Link copied to clipboard

Properties

Link copied to clipboard
var command: <Error class: unknown class>
Link copied to clipboard

Optional collection of build step execution conditions

Link copied to clipboard
var dockerImage: <Error class: unknown class>

Specifies which Docker image to use for running this build step. I.e. the build step will be run inside specified docker image, using 'docker run' wrapper.

Link copied to clipboard
var dockerImagePlatform: <Error class: unknown class>

Specifies which Docker image platform will be used to run this build step.

Link copied to clipboard
var dockerPull: <Error class: unknown class>

If enabled, "pull image" command will be run before docker run.

Link copied to clipboard
var dockerRunParameters: <Error class: unknown class>

Additional docker run command arguments

Link copied to clipboard

Specifies whether the step is enabled, true by default

Link copied to clipboard
var environment: <Error class: unknown class>
Link copied to clipboard
Link copied to clipboard
var id: String?

Optional id of the step. Usually the id is not required, however if a build configuration inherits from a template and wants to override a build step defined there, then both steps should have the same id.

Link copied to clipboard

Build step name

Link copied to clipboard
Link copied to clipboard
var pythonVersion: <Error class: unknown class>
Link copied to clipboard

Build step type

Link copied to clipboard
var workingDir: <Error class: unknown class>

Build working directory for python run, specify it if it is different from the checkout directory.

Functions

Link copied to clipboard
fun booleanParameter(customName: String? = null, trueValue: String? = "true", falseValue: String? = "false"): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
fun clear()
Link copied to clipboard

Deletes all configured build step conditions

Link copied to clipboard
fun <T : CompoundParam<T>> compoundParameter(customName: String? = null): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
Link copied to clipboard
fun <T : Parametrized> copyParamsTo(target: T): T

Copies parameters of this object to the specified target

Link copied to clipboard
open fun create(): BuildStep

Creates an instance of this build step via reflection using a no argument constructor, used during copying. Throws an error if this class doesn't have a default constructor. Subclasses can override it to create an instance without using a default constructor.

Link copied to clipboard
Link copied to clipboard
fun doubleParameter(customName: String? = null): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
fun <E : Enum<E>> enumParameter(customName: String? = null, mapping: Map<E, String?>? = null): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
Link copied to clipboard
fun findRawParam(paramName: String): Parameter?
Link copied to clipboard
Link copied to clipboard
fun hasParam(paramName: String): Boolean
Link copied to clipboard
fun intParameter(customName: String? = null): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun param(name: String, value: String)

Adds parameter with specified name and value

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun removeRawParam(paramName: String)
Link copied to clipboard
Link copied to clipboard
open fun stringParameter(customName: String? = null): <Error class: unknown class><Parametrized, <Error class: unknown class><Parametrized, T?>>
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun validate(consumer: ErrorConsumer)

Validates this object and reports found errors to the provided consumer

Link copied to clipboard