PythonBuildStep
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%"
}
}
Content copied to clipboard }
}
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"
}
}
Content copied to clipboard }
}
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()
}
}
Content copied to clipboard }
}
See also
Constructors
Types
Docker image platforms
Functions
Deletes all configured build step conditions
Configures build step conditions
Copies parameters of this object to the specified target
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.
Validates this object and reports found errors to the provided consumer
Properties
If enabled, "pull image" command will be run before docker run.
Build working directory for python run, specify it if it is different from the checkout directory.