Skip to content

Environment

Declares which environment this job interacts with.

To declare the environment, see Job.environment.

Types

EnvironmentAction

EnvironmentTier

Functions

action

Specify how this job interacts with the environment. See EnvironmentAction.

Example
val verifyQa by job {
    script {
        // …
    }

    environment {
        name("qa")
        action(EnvironmentAction.Verify)
    }
}
External resources

name

fun name(name: String)

Declares the name of the environment, as it will be displayed in the GitLab UI.

val deploy-qa by job {
    script {
        // …
    }

    environment {
        name("qa")
        url("https://qa.your.app/dashboard")
    }
}
External resources

stopJob

fun stopJob(stopJob: Job)

Specifies a stopJob that will be executed once the environment should be stopped.

The stop job should have the same configuration but without a declared url.

Example
val stopQa by job {
    script {
        // …
    }

    environment {
        name("qa")
    }
}

val deployQa by job {
    script {
        // …
    }

    environment {
        name("qa")
        url("https://qa.your.app/dashboard")
        onStop(stopQa)
    }
}
External resources

tier

Declares which tier this job deploys.

Example
val verifyQa by job {
    script {
        // …
    }

    environment {
        name("qa")
        tier(EnvironmentTier.Testing)
    }
}
External resources

toYaml

open override fun toYaml(): Yaml

Converts this object into a Yaml object.

url

fun url(url: String)

Declares the URL on which the deployed environment is available.

Example
val deploy-qa by job {
    script {
        // …
    }

    environment {
        name("qa")
        url("https://qa.your.app/dashboard")
    }
}
Example: dynamic URL

The URL can be generated by the job itself by combining this feature with Artifacts.dotenv:

val deploy-qa by job {
    script {
        shell("QA_URL=$(./generate-url) >>qa.env")
    }

    artifacts {
        dotenv("qa.env")
    }

    environment {
        name("qa")
        url($$"$QA_URL")
    }
}
External resources