Skip to content

Instantly share code, notes, and snippets.

@SamErde
Last active May 20, 2025 07:14
Show Gist options
  • Save SamErde/4ae30a56f8a805507b017212b811f64f to your computer and use it in GitHub Desktop.
Save SamErde/4ae30a56f8a805507b017212b811f64f to your computer and use it in GitHub Desktop.
# Check if environment variables indicate running in a CI/CD environment.
$CiCdEnvironment = @(
# GitHub Actions
$env:GITHUB_ACTIONS -eq 'true',
# GitLab CI
$env:GITLAB_CI -eq 'true',
# Azure DevOps
$env:TF_BUILD -eq 'true',
# Bitbucket Pipelines
$null -ne $env:BITBUCKET_BUILD_NUMBER,
# Jenkins
$null -ne $env:JENKINS_URL,
# CircleCI
$env:CIRCLECI -eq 'true',
# Travis CI
$env:TRAVIS -eq 'true',
# TeamCity
$null -ne $env:TEAMCITY_VERSION
)
# Check if environment variables indicate running within a container environment.
$ContainerEnvironment = @(
# Check for Docker
(Test-Path -Path '/.dockerenv'),
# Check for common container environment variables
$env:KUBERNETES_SERVICE_HOST -ne $null,
# Check for Windows container
$env:CONTAINER -eq 'true'
)
$NonInteractive = if (
(-not [Environment]::UserInteractive) -or
([Environment]::GetCommandLineArgs() -match 'NonInteractive') -or
$CiCdEnvironment -or
$ContainerEnvironment
) {
$true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment