This project automates workflows similar to CI/CD processes, allowing users to define and execute build, test, deploy, and undeploy stages through a YAML-configured pipeline and a command-line interface.
- Automate build, test, deploy, and undeploy processes.
- Easy configuration with
pipeline.yaml
. - CLI support for easy interaction.
- Python 3.6+
- PyYAML
Clone the repository:
git clone https://github.com/dotemup/pipeline_cli.git
cd pipeline_cli
Install the package:
pip install .
Execute a pipeline stage: pipeline [-d ] [-f ] [--rollback]
<action>
: The pipeline stage (setup
,build
,test
,deploy
,undeploy
).-d <directory>
: Directory containingpipeline.yaml
(default: current directory).-f <file>
: The pipeline configuration file (default:pipeline.yaml
).--rollback
: Execute the rollback stage for the specified action(s).
While in a directory that contains a pipeline.yaml:
pipeline build
Or run multiple stages in order:
pipeline build test deploy
The pipeline.yaml
file defines the steps to be executed for each stage of your pipeline. Available stages are: setup, build, test, deploy, and undeploy. Here's how to structure your pipeline.yaml
:
setup:
- echo "Installing dependencies"
build:
- echo "Building project"
test:
- echo "Running tests"
deploy:
- echo "Deploying to environment"
undeploy:
- echo "Removing from environment"
Nested calls allow you to execute a pipeline within another pipeline, facilitating complex workflows that require multiple stages or steps to be executed in sequence or conditionally. To implement nested calls, you specify a command to run another pipeline configuration from within a pipeline.yaml
stage.
For instance, if you have a primary pipeline that requires executing a secondary pipeline as part of the build process, you can specify this directly within your build
stage using the pipeline command followed by the desired action and any relevant options such as directory or configuration file.
This approach enables you to modularize your workflows, making them more manageable and reusable across different projects or environments. Remember, when designing nested calls, to ensure that your pipelines are structured in a way that avoids circular dependencies to prevent infinite execution loops.
setup:
- pipeline setup -d some_subdir
- pipeline setup -d another_subdir -f setup.yaml
build:
- pipeline build -d some_subdir
- pipeline build -d another_subdir -f build.yaml
test:
- pipeline test -d some_subdir
- pipeline test -d another_subdir -f test.yaml
deploy:
- pipeline deploy -d some_subdir
- pipeline deploy -d another_subdir -f deploy.yaml
undeploy:
- pipeline undeploy -d some_subdir
- pipeline undeploy -d another_subdir -f undeploy.yaml
The pipeline_cli
tool can utilize environment variables if they are set before running the pipeline. This functionality is supported on both Unix-like systems and Windows.
In Unix-like systems, environment variables can be set using the export
command and are interpreted with the $ENV
format. Here’s an example where the TEST
variable is set to hello
and then used to print hello world
.
build:
- echo "$TEST world"
In Windows, environment variables can be set using the set
command and are interpreted with the %ENV%
format. Here’s an example where the TEST variable is set to hello and then used to print hello world.
build:
- echo "%TEST% world"
The following environment variables are set at the start of each pipeline execution and can be used as needed:
PIPELINE_ID
: A unique identifier for the current pipeline execution.PIPELINE_RELEASE_VERSION
: The release version of the current pipeline execution.
These variables are automatically populated and can be accessed in your scripts. Useful for automatically setting unique build tags and handy for logging.
In pipeline.yaml
, you can define variables and reusable content to simplify your configuration and avoid duplication. This section explains how to use generic YAML properties and anchors, and how to reference them within your pipeline configuration.
Variables can be defined at the top of your pipeline.yaml
file and referenced within any command using the syntax ${VARIABLE_NAME}
. This allows for dynamic command configurations based on the values of the variables.
MY_VARIABLE: "hello world"
build:
- echo ${MY_VARIABLE}
YAML anchors (&
) and aliases (*
) allow you to define a block of commands once and reuse them elsewhere in your YAML file. This is useful for common setup, teardown, or utility operations that need to be repeated across different stages.
You can define a reusable block with an anchor (&
), and then reference it with an alias (*
) in one or more stages:
custom_setup: &custom_setup
- command1
- command2
build:
- *custom_setup
- build_command
deploy:
- *custom_setup
- deploy_command
This setup defines a list of commands under custom_setup
using an anchor named custom_setup
. Both build
and deploy
stages then reuse these commands via the *custom_setup
alias, followed by stage-specific commands.
Using variables, environment variables, and YAML anchors and aliases, you can create flexible and maintainable pipeline configurations that adapt to different needs and environments with minimal duplication.
The .rollback
modifier can be used after a stage and is triggered with the --rollback
argument when executing the pipeline. This is particularly handy for failed builds, allowing you to quickly rollback without undeploying the entire application.
To define a rollback stage in your pipeline, add the .rollback
modifier after a stage. Here’s an example:
build:
- echo "Building application..."
build.rollback:
- echo "Rolling back to the previous version..."
You can trigger the rollback stage by executing the pipeline with the --rollback argument:
pipeline build --rollback
Combine this with the predefined environment variables or your own system variables.
Multiple stages can have the modifier and can be called together:
build:
- echo "hello"
build.rollback:
- echo "lorem"
deploy:
- echo "world"
deploy.rollback:
- echo "ipsum"
Running the build
and deploy
stages in the example provided results in printing hello
and then printing world
.
pipeline build deploy
Running the build
and deploy
stages with the --rollback
argument in the example provided results in printing lorem
and then printing ipsum
.
pipeline build deploy --rollback
Contributions are welcome! Please fork the repository and open a pull request with your changes.
This project is licensed under the MIT License - see the LICENSE file for details.