Skip to content

Jenkins Hoja de referencia

Servidor de automatización para compilar, probar y desplegar software.

01

Pipeline

Declarativo

Pipeline declarativo con el DSL de Groovy.

jenkins
pipeline {
  agent any
  stages {
    stage("Build") {
      steps { sh "npm run build" }
    }
    stage("Test") {
      steps { sh "npm test" }
    }
    stage("Deploy") {
      steps { sh "deploy.sh" }
    }
  }
}

Entorno

Variables de entorno y credenciales.

jenkins
pipeline {
  environment {
    NODE_ENV = "production"
    API_KEY = credentials("api-key")
  }
}
02

Características

When

Ejecución condicional de stages.

jenkins
stage("Deploy") {
  when { branch "main" }
  steps { sh "deploy.sh" }
}

Post

Acciones posteriores a la compilación.

jenkins
post {
  success { echo "Build passed" }
  failure { emailext to: "[email protected]", subject: "Build failed" }
  always { archiveArtifacts "dist/**" }
}

Parallel

Ejecución de stages en paralelo.

jenkins
stages {
  stage("Test") {
    parallel {
      stage("Unit") { steps { sh "npm run test:unit" } }
      stage("E2E") { steps { sh "npm run test:e2e" } }
    }
  }
}

Was this helpful?