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%"
}
}
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
Types
Properties
Optional collection of build step execution conditions
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.
Specifies which Docker image platform will be used to run this build step.
If enabled, "pull image" command will be run before docker run.
Additional docker run command arguments
Build step execution mode
Build working directory for python run, specify it if it is different from the checkout directory.
Functions
Deletes all configured build step conditions
Configures build step conditions
Copies parameters of this object to the specified target
Validates this object and reports found errors to the provided consumer