Post

2 followers Follow
0
Avatar

How to include sepcic required environments based on some evaluation ?

How to include sepcic required environments based on some evaluation ?

Use case:

For ex : Lets say I want to create a release with APP 1 with DEV, QA ,STAGE, PROD environments but APP 2 with DEV, QA, PROD only, so want to make a decision when creating a release based on app name.

If APP1 is merged on the release branch it should trigger a release and grab DEV, QA ,STAGE, PROD environment phases in the release with required release variables.

Thanks

Vasanth

 

Vasanth

Please sign in to leave a comment.

8 comments

0
Avatar

Hi Vasanth

One way to approach it would be to wrap all tasks in each phase in a SequentialGroup and put a precondition on the group.

You can create a boolean variables for each phase, for example ${executeDEV}, ${executeQA}, etc.

Then the precondition would be 

  ${executeDEV}

Kind regards,

Hes Siemelink 0 votes
0
Avatar

Hey Hes,

 

Thats a good idea, lets say i want to include sepcific tasks based on app, 

Use case : if app1 needs script task, and app2 needs jenkins task, how to include the tasks in required phase on a runtime.

 

Thanks

Vasanth

Vasanth 0 votes
0
Avatar

Here's an example of a release with conditional phases. Each phase has a corresponding boolean variable that is used in the precondition on the main task of the phase. The main task is a sequential group that contains all tasks. 

You can use the same approach with boolean variables and preconditions to determine whether individual tasks should be executed or not. For example Jenkins task or Script task -- just put then in both with a precondition.

You can even put arbitrary code with API calls and stuff inside a precondition block, so you're not forced to use the variables and the check can be more dynamic.

See https://docs.xebialabs.com/xl-release/how-to/set-a-precondition-on-a-task.html

 

 Here's the code -- it's in groovy syntax because the forum doesn't allow attachments.

 

Hes Siemelink 0 votes
0
Avatar
xlr {
release('Conditional phases') {
variables {
booleanVariable('executeDEV') {
label 'Execute DEV phase'
description 'If unchecked, DEV phase will be skipped'
value true
}
booleanVariable('executeQA') {
label 'Execute QA phase'
description 'If unchecked, QA phase will be skipped'
value true
}
booleanVariable('executeSTAGE') {
label 'Execute STAGE phase'
description 'If unchecked, STAGE phase will be skipped'
value true
}
booleanVariable('executePROD') {
label 'Execute PROD phase'
description 'If unchecked, PROD phase will be skipped'
value true
}
}
scheduledStartDate Date.parse("yyyy-MM-dd'T'HH:mm:ssZ", '2018-10-26T09:00:00+0200')
phases {
phase('DEV') {
color '#009CDB'
tasks {
parallelGroup('DEV phase') {
precondition '${executeDEV}'
tasks {
manual('Task 1') {

}
manual('Task 2') {

}
manual('Task 3') {

}
}
}
}
}
phase('QA') {
color '#dd4b39'
tasks {
parallelGroup('QA phase') {
precondition '${executeQA}'
tasks {
manual('Task 1') {

}
manual('Task 2') {

}
manual('Task 3') {

}
}
}
}
}
phase('STAGE') {
color '#ff9e3b'
tasks {
parallelGroup('STAGE phase') {
precondition '${executeSTAGE}'
tasks {
manual('Task 1') {

}
manual('Task 2') {

}
manual('Task 3') {

}
}
}
}
}
phase('PROD') {
color '#68b749'
tasks {
parallelGroup('PROD phase') {
precondition '${executePROD}'
tasks {
manual('Task 1') {

}
manual('Task 2') {

}
manual('Task 3') {

}
}
}
}
}
}
}
}
Hes Siemelink 0 votes
0
Avatar

Hello Hes,

 

Yes, the idea is what i am currently following,  but the other app team shouldnot see the skipped phases or tasks.

 

For ex: If app1 doesnt need prod phse, they should see the prod phase in the release rather than skipping, that way it will be specific to that app.

 

Thanks

vasanth

Vasanth 0 votes
0
Avatar

Hi Vasanth

You can add a script task at the beginning of the release that removes phases using the public API.

For example, here's a Jython task that removes the PROD phase, based on a checkbox variable called 'executePROD'

if releaseVariables['executePROD'] == False:
prodPhases = phaseApi.searchPhasesByTitle('PROD', release.id)

for phase in prodPhases:
phaseApi.deletePhase(phase.id)

Hope this helps.

Kind regards,

Hes Siemelink 0 votes
0
Avatar

Hello Hes,

 

This is really helpfull, but i have one other use case with this. Please can you help me with this.

 

For ex : If app1 needs task1, but not task2, whereas the task1 name contains RBD, so it is required, but task2 name doesnot contain RBD, so delete that task.

 

THanks

Vasanth

Vasanth 0 votes
0
Avatar

Hi Vasanth

I would recommend to use preconditions in this case, that keeps the execution of the release flow more predictable.

Otherwise, please take a look at the Jython API Reference and experiment with some scripting.

Kind regards,

Hes Siemelink 0 votes