Jenkins Integration Recipe
Implementation Reference
Source Files:
packages/core/src/core/execution-engine.ts
- Core execution engineapps/xec/src/commands/run.ts
- Script executionapps/xec/src/main.ts
- CLI entry point
Key Functions:
$.execute()
- Command executionRunCommand.execute()
- Script runnermain()
- CLI initialization
Overview
This recipe demonstrates how to integrate Xec with Jenkins for continuous integration and deployment pipelines using both declarative and scripted pipelines.
Declarative Pipeline
Basic Jenkins Pipeline
// Jenkinsfile
pipeline {
agent any
environment {
XEC_VERSION = 'latest'
NODE_VERSION = '18'
}
tools {
nodejs "${NODE_VERSION}"
}
stages {
stage('Setup') {
steps {
sh 'npm install -g @xec-sh/cli@${XEC_VERSION}'
sh 'xec --version'
sh 'npm ci'
}
}
stage('Validate') {
steps {
sh 'xec config validate'
sh 'xec inspect --targets'
}
}
stage('Test') {
parallel {
stage('Unit Tests') {
steps {
sh 'xec test:unit --coverage'
}
}
stage('Integration Tests') {
steps {
sh 'xec test:integration'
}
}
stage('Lint') {
steps {
sh 'xec lint --fix'
}
}
}
post {
always {
junit 'test-results/**/*.xml'
publishHTML([
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'coverage',
reportFiles: 'index.html',
reportName: 'Coverage Report'
])
}
}
}
stage('Build') {
steps {
sh 'xec build --env=production'
archiveArtifacts artifacts: 'dist/**/*', fingerprint: true
}
}
stage('Deploy to Staging') {
when {
branch 'develop'
}
steps {
sh 'xec deploy staging --auto-approve'
}
}
stage('Deploy to Production') {
when {
branch 'main'
}
input {
message "Deploy to production?"
ok "Deploy"
parameters {
string(name: 'VERSION', defaultValue: 'latest', description: 'Version to deploy')
}
}
steps {
sh "xec deploy production --version=${params.VERSION}"
}
}
}
post {
success {
slackSend(
color: 'good',
message: "Build Successful: ${env.JOB_NAME} - ${env.BUILD_NUMBER}"
)
}
failure {
slackSend(
color: 'danger',
message: "Build Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER}"
)
}
always {
cleanWs()
}
}
}