Skip to content

VitexSoftware/jenkins-multiflexi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jenkins MultiFlexi Plugin

Jenkins Shared Library for running MultiFlexi applications from Jenkins pipeline.

Features

  • Schedule MultiFlexi runtemplate for immediate execution
  • Automatic waiting for job completion with configurable timeout
  • Get results including exit code, stdout and stderr
  • Support for creating runtemplate if it doesn't exist
  • Pass configuration and environment variables to MultiFlexi jobs

Requirements

  • Jenkins Pipeline
  • multiflexi-cli >= 2.2.0 installed on Jenkins agent
  • Access to MultiFlexi database from Jenkins agent

Installation

1. Add Library to Jenkins

In Jenkins configuration (Manage Jenkins → Configure System → Global Pipeline Libraries):

  1. Add a new library with name e.g. multiflexi
  2. Set Source Code Management to Git
  3. Enter the URL of this repository
  4. Check "Load implicitly" if you want to load the library automatically

2. Usage in Jenkinsfile

@Library('multiflexi') _

pipeline {
    agent any
    
    stages {
        stage('Build') {
            steps {
                // Your build process
                sh 'make build'
                sh 'make publish-packages'
            }
        }
        
        stage('Deploy & Test') {
            steps {
                script {
                    def result = runMultiFlexi(
                        company: 'mycompany',
                        appId: '123',
                        createIfNotExists: true,
                        runtimeplateName: 'Deploy and Test',
                        config: [
                            'package_name': 'my-app',
                            'version': "${env.BUILD_NUMBER}"
                        ],
                        timeout: 1800,
                        pollInterval: 10
                    )
                    
                    echo "Job completed with exit code: ${result.exitcode}"
                }
            }
        }
    }
}

Usage

Basic Usage

Run an existing runtemplate:

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456'
)

With Configuration

Pass configuration to MultiFlexi application:

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456',
    config: [
        'param1': 'value1',
        'param2': 'value2',
        'environment': 'production'
    ]
)

With Custom Timeout

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456',
    timeout: 3600,        // 1 hour
    pollInterval: 5       // check every 5 seconds
)

Automatic RunTemplate Creation

If runtemplate doesn't exist, it will be created automatically:

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    createIfNotExists: true,
    runtimeplateName: 'CI/CD Deployment',
    config: [
        'deploy_target': 'production'
    ]
)

Pass Environment Variables

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456',
    env: [
        'CUSTOM_VAR': 'value',
        'DEBUG': '1'
    ]
)

Select Executor

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456',
    executor: 'Docker'  // or 'Native', 'Kubernetes', etc.
)

Working with Results

def result = runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    runtemplateId: '456'
)

echo "Job ID: ${result.id}"
echo "Status: ${result.status}"
echo "Exit code: ${result.exitcode}"
echo "Start time: ${result.begin}"
echo "End time: ${result.end}"

if (result.stdout) {
    echo "=== Output ==="
    echo result.stdout
}

if (result.stderr) {
    echo "=== Errors ==="
    echo result.stderr
}

// You can also process the output
if (result.stdout?.contains('SUCCESS')) {
    echo "Deployment successful!"
}

Complete CI/CD Workflow Example

@Library('multiflexi') _

pipeline {
    agent any
    
    environment {
        APP_ID = '123'
        COMPANY = 'mycompany'
    }
    
    stages {
        stage('Build') {
            steps {
                sh 'make build'
            }
        }
        
        stage('Publish Packages') {
            steps {
                sh 'make publish-deb'
                sh 'make publish-rpm'
            }
        }
        
        stage('Install & Test') {
            steps {
                script {
                    try {
                        def result = runMultiFlexi(
                            company: env.COMPANY,
                            appId: env.APP_ID,
                            createIfNotExists: true,
                            runtimeplateName: "${env.JOB_NAME}-install-test",
                            config: [
                                'package': 'my-application',
                                'version': env.BUILD_NUMBER,
                                'test_suite': 'integration'
                            ],
                            timeout: 1800,
                            pollInterval: 10
                        )
                        
                        // Save results for archiving
                        writeFile file: 'multiflexi-output.txt', text: result.stdout ?: ''
                        writeFile file: 'multiflexi-errors.txt', text: result.stderr ?: ''
                        
                        archiveArtifacts artifacts: 'multiflexi-*.txt', allowEmptyArchive: true
                        
                        if (result.exitcode == 0) {
                            currentBuild.result = 'SUCCESS'
                        } else {
                            currentBuild.result = 'FAILURE'
                            error("MultiFlexi job failed with exit code ${result.exitcode}")
                        }
                        
                    } catch (Exception e) {
                        currentBuild.result = 'FAILURE'
                        error("Failed to run MultiFlexi job: ${e.message}")
                    }
                }
            }
        }
        
        stage('Deploy Production') {
            when {
                branch 'main'
            }
            steps {
                script {
                    def result = runMultiFlexi(
                        company: env.COMPANY,
                        appId: env.APP_ID,
                        runtemplateId: '789',  // Production deployment template
                        config: [
                            'version': env.BUILD_NUMBER,
                            'environment': 'production'
                        ],
                        timeout: 3600
                    )
                    
                    echo "Deployed to production with exit code: ${result.exitcode}"
                }
            }
        }
    }
    
    post {
        always {
            cleanWs()
        }
    }
}

Parameters

Required Parameters

  • company (String): Company slug in MultiFlexi
  • appId (String): Application ID in MultiFlexi

Optional Parameters

  • runtemplateId (String): RunTemplate ID. If not provided and createIfNotExists is true, a new one will be created
  • runtimeplateName (String): Name for new runtemplate (default: ${JOB_NAME}-${appId})
  • createIfNotExists (Boolean): Create runtemplate if it doesn't exist (default: false)
  • config (Map): Application configuration as key-value pairs
  • env (Map): Environment variable overrides as key-value pairs
  • executor (String): Executor for execution (default: 'Native')
  • timeout (Integer): Timeout in seconds (default: 3600)
  • pollInterval (Integer): Status check interval in seconds (default: 10)

Return Value

The plugin returns a Map with the following data from MultiFlexi job:

  • id: Job ID
  • status: Job status ('success', 'failed', 'running', etc.)
  • exitcode: Process exit code
  • stdout: Standard output
  • stderr: Error output
  • begin: Start time
  • end: End time
  • other fields according to MultiFlexi API

Troubleshooting

MultiFlexi-cli not found

Make sure that multiflexi-cli is installed on Jenkins agent and is available in PATH.

sh 'which multiflexi-cli'
sh 'multiflexi-cli --version'

Timeout while waiting for completion

Increase the timeout parameter value:

runMultiFlexi(
    company: 'mycompany',
    appId: '123',
    timeout: 7200  // 2 hours
)

Job failed

Check stderr output for details:

def result = runMultiFlexi(...)
if (result.exitcode != 0) {
    echo "Job failed with errors:"
    echo result.stderr
}

Development

Project Structure

jenkins-multiflexi/
├── src/
│   └── com/
│       └── vitexsoftware/
│           └── multiflexi/
│               └── MultiFlexiClient.groovy   # Main class for calling multiflexi-cli
├── vars/
│   └── runMultiFlexi.groovy                  # Pipeline DSL step
└── README.md                                 # Documentation

Local Testing

For testing you can use Jenkins Pipeline Unit Testing Framework or run in real Jenkins environment.

License

MIT

Author

VitexSoftware

Support

For bug reports and feature requests use the project's issue tracker.

About

Jenkins Shared Library for running MultiFlexi applications from Jenkins pipeline

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages