Skip to main content

A package for reading Jenkinsfile-like pipeline files

Project description

Pipeline Reader

About

pipeline-reader is a package designed to make it easier to user Jenkinsfile-like pipeline files in Python projects. While JSON and YAML are generally sufficient for this task, there may be times where you want to execute code, which JSON and YAML are not well-suited for. In this case, pipeline-reader allows you to define stages containing Python code which are then run sequentially.

Examples

Writing a Pipeline

A basic pipeline consists of a pipeline block containing stages as follows:

pipeline {
    stages {
        stage('foo') {
            print('do something')
        }
    }
}

You can then add an options block like so

pipeline {
    options {
        "foo1": "bar1"
        "foo2": "bar2"
    }
    stages {
        stage('foo') {
            print('do something')
        }
    }
}

These options will then be stored in a dictionary and made available via the Pipeline object that pipeline-reader returns In addition, the code context carries over between stages, so running

pipeline {
    stages {
        stage('foo') {
            variable = True
        }
        stage('bar') {
            print(variable)
        }
    }
}

will output True. Finally, Python and C style comments are both supported inside the pipeline files.

# this will be ignored when the file is loaded in
pipeline {
    stages {
        // this will also be ignored
        stage('foo') {
            # even comments inside of stages are stripped out
            print('do something')
        }
    }
}

Using pipeline-reader in an Application

To utilize pipeline-reader, you'll want to use something like what is shown below

import pipeline_reader

# this will load your pipeline
with open('filename.pipeline') as f:
    pipeline = pipeline_reader.load(f)

# this will execute your pipeline
pipeline_reader.run(pipeline, globals(), locals())

To Do

  • Parse pipeline file
  • Run loaded pipelines
  • Pre-stage
  • Post-stage
  • Catch stage success
  • Catch stage failure
  • Allow loading of arbitrary block types

Contact

If you have any questions or concerns, please reach out to me (John Carter) at jfcarter2358@gmail.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pipeline-reader-0.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

pipeline_reader-0.0.1-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page