Jenkins Pipeline Generator#

Generate Jenkinsfile scripts using the declarative pipeline syntax. Pipelines leverage the DevOps-OS container for a consistent build environment.


Basic Usage#

python -m cli.devopsos scaffold jenkins --name "my-app" --type complete

Output: Jenkinsfile (default)
Change the output path with --output <path>.


Options#

OptionDefaultDescription
--name NAMEDevOps-OSPipeline name
--type TYPEcompletebuild | test | deploy | complete | parameterized
--languages LANGSpython,javascriptComma-separated: python, java, javascript, go
--kubernetesoffAdd Kubernetes deploy stage
--registry URLdocker.ioContainer registry URL
--k8s-method METHODkubectlkubectl | kustomize | argocd | flux
--output FILEJenkinsfileOutput file path
--custom-values FILE(none)Path to custom values JSON file
--image IMAGEdocker.io/yourorg/devops-os:latestDevOps-OS container image
--scm SCMgitSource control: git | svn | none
--parametersoffAdd runtime parameters (auto-enabled for --type parameterized)
--env-file FILE(cli dir)Path to devcontainer.env.json

All options can be set via environment variables prefixed DEVOPS_OS_JENKINS_.


Pipeline Types#

TypeDescription
buildFocuses on building and packaging your application
testFocuses on running tests
deployFocuses on deploying to the target environment
completeCombines build, test, and deploy stages
parameterizedAdds runtime parameters for interactive runs

Examples#

Complete Java pipeline#

python -m cli.devopsos scaffold jenkins --name my-app --languages java --type complete
# Output: Jenkinsfile

Parameterized deployment pipeline#

python -m cli.devopsos scaffold jenkins \
  --name "Deployment" \
  --languages go \
  --kubernetes --k8s-method argocd \
  --parameters
# Output: Jenkinsfile

Custom output location#

python -m cli.devopsos scaffold jenkins \
  --name my-app \
  --languages python \
  --output pipelines/Jenkinsfile
# Output: pipelines/Jenkinsfile

Generated Pipeline Structure#

pipeline {
    agent {
        docker {
            image 'docker.io/yourorg/devops-os:latest'
            args '-v /var/run/docker.sock:/var/run/docker.sock -u root'
        }
    }
    parameters {
        booleanParam(name: 'PYTHON_ENABLED', defaultValue: true, ...)
        choice(name: 'ENVIRONMENT', choices: ['dev', 'test', 'staging', 'prod'], ...)
        string(name: 'IMAGE_TAG', defaultValue: 'latest', ...)
    }
    environment {
        REGISTRY     = 'docker.io'
        IMAGE_NAME   = 'myorg/my-app'
    }
    stages {
        stage('Build') { ... }
        stage('Test')  { ... }
        stage('Deploy') { ... }
    }
    post {
        always { cleanWs() }
        failure { mail to: 'team@example.com', subject: 'Build failed' }
    }
}

Parameterized Pipelines#

Parameterized pipelines accept runtime inputs:

parameters {
    booleanParam(name: 'PYTHON_ENABLED', defaultValue: true,
                 description: 'Enable Python tools')
    choice(name: 'ENVIRONMENT',
           choices: ['dev', 'test', 'staging', 'prod'],
           defaultValue: 'dev')
    string(name: 'IMAGE_TAG', defaultValue: 'latest',
           description: 'Container image tag')
}

Credentials Management#

The generated pipeline uses Jenkins credentials:

withCredentials([
    file(credentialsId: 'kubeconfig', variable: 'KUBECONFIG')
]) {
    sh 'kubectl apply -f ./k8s/deployment.yaml'
}

withCredentials([
    usernamePassword(
        credentialsId: 'registry-credentials',
        usernameVariable: 'REGISTRY_USER',
        passwordVariable: 'REGISTRY_PASSWORD'
    )
]) {
    sh 'docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD'
}

Environment Variables#

export DEVOPS_OS_JENKINS_NAME="API Service"
export DEVOPS_OS_JENKINS_TYPE="complete"
export DEVOPS_OS_JENKINS_LANGUAGES="python,go"
export DEVOPS_OS_JENKINS_KUBERNETES="true"
export DEVOPS_OS_JENKINS_K8S_METHOD="kustomize"
export DEVOPS_OS_JENKINS_PARAMETERS="true"

python -m cli.devopsos scaffold jenkins
# Output: Jenkinsfile

Custom Values File#

{
  "build": {
    "timeout_minutes": 30,
    "tool_options": {
      "maven": { "goals": ["clean", "package"] }
    }
  },
  "credentials": {
    "docker": "docker-registry-credentials",
    "kubernetes": "kubeconfig",
    "argocd": "argocd-credentials"
  },
  "notifications": {
    "slack": { "channel": "deployments", "failure": true }
  }
}
python -m cli.devopsos scaffold jenkins --custom-values advanced-config.json
# Output: Jenkinsfile

Best Practices#

  1. Use --parameters for environments that benefit from manual approval gates
  2. Store credentials in Jenkins Credentials Store, never in the Jenkinsfile
  3. Use --env-file to align with your dev container configuration
  4. Start with --type complete and remove stages you don’t need
  5. Set appropriate timeouts in --custom-values for long builds