This article helps you get the most out of the NextGen platform
Introduction
Currently, this feature is behind a Feature Flag. Contact Harness Support to enable the feature.
Looping strategies enable you to run a Stage or Step multiple times with different inputs. This eliminates the need to copy the same Stage or Step for each variation you need. It also makes the Pipeline more readable, clean, and easy to maintain.
Looping strategies enable use cases such as:
- Deploy multiple services specifying it only in your git repository.
- Identify changes in your git repository and run steps/stages only on changed folders.
- You want to test a UI feature in multiple browsers and platforms. You can define a matrix that specifies the browsers and platforms to test.
Deploy multiple services dynamically
In this example, I’ll iterate through the folders of a repository I created and print its content in the next step; your use case will probably be more complex, using helm, terraform, and others to deploy.
The only requirement in this example is git installed on your delegate.
If you don’t know how to install binaries in your delegate, take a look at Install Software on the Delegate with Initialization Scripts - Harness.io Docs.
pipeline:
name: dynamically-deploying-services
identifier: dynamicallydeployingservices
projectIdentifier: teste
orgIdentifier: default
tags: {}
stages:
- stage:
name: Deploy multiple services
identifier: Deploy_multiple_services
description: ""
type: Custom
spec:
execution:
steps:
- step:
type: ShellScript
name: Retrieve folder list
identifier: Retrieve_folder_list
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: |-
set -e
REPOSITORY_NAME="<+pipeline.variables.REPOSITORY_NAME>"
rm -rf $REPOSITORY_NAME
git clone https://github.com/guirociozanini/$REPOSITORY_NAME.git
cd $REPOSITORY_NAME
FOLDERS=$(ls -d */ | tr '\n' ',' | xargs echo | sed 's/ / /g')
environmentVariables: []
outputVariables:
- name: FOLDERS
type: String
value: FOLDERS
timeout: 10m
- step:
type: ShellScript
name: Deploy service
identifier: Deploy_service
spec:
shell: Bash
onDelegate: true
source:
type: Inline
spec:
script: |-
cd <+pipeline.variables.REPOSITORY_NAME>/<+repeat.item>
ls -a
echo "deploying service: <+repeat.item>"
environmentVariables: []
outputVariables: []
timeout: 10m
failureStrategies: []
strategy:
repeat:
items: <+<+steps.Retrieve_folder_list.output.outputVariables.FOLDERS>.split(",")>
tags: {}
variables:
- name: REPOSITORY_NAME
type: String
description: ""
value: lab-iterate-folders-dynamically
Notes
- GitHub Repository for this example: GitHub - guirociozanini/lab-iterate-folders-dynamically
- An essential step for this to work is that a string list was converted to an array using a JEXL method
Conclusion
This article covers in a fundamental way, how to get the most out of the NextGen platform. If you have any suggestions on how to improve this article, or helpful and specific examples of permissions related issues that may be of use to others, please leave a comment with the information as this document is intended to evolve over time.
If this article cannot resolve your issue, don’t hesitate to contact us here: support@harness.io – or through the Zendesk portal in Harness SaaS.