Project and Portfolio Management Practitioners Forum
cancel

Anyway to use bash scripts in execution steps

SOLVED
Go to solution
Highlighted
TurboMan
Honored Contributor.

Anyway to use bash scripts in execution steps

Hi,

 

In an execution step I am trying to use some bash scripts but somehow I could not manage.

I am not sure if I am doing something wrong or it is not supported.

My example is as follows.

 

if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ]
then
  ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
  ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
fi

ksc_comment "done"

 

It comes up with an error as

"Unknown or out of sequence command

[if [ "Technical Infrastructure Old" = "Technical Infrastructure" ]]

" in the log.

 

Any help is appreciated

 

Regards

T.M.

 

9 REPLIES
dlinetsk
Super Contributor.

Re: Anyway to use bash scripts in execution steps

I think you are missing ";" in number of places and closing "]".

try this:

if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ] ];
then
ksc_itg_run_sql QUERY_STRING="SELECT project_type_id FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old" ;
fi
ksc_comment "done"


Thanks,
TurboMan
Honored Contributor.

Re: Anyway to use bash scripts in execution steps

Thanks,

 

But still the same problem.

 

dlinetsk
Super Contributor.
Solution

Re: Anyway to use bash scripts in execution steps

Can you please post the full command you are using?

 

I think you can specify an IF condition within a command scope - you cannot use it outside of command scope. Based on your original post your IF statment is out of command scope. 

 

 

For out of command scope there is a Condition parameter (see attached).

TurboMan
Honored Contributor.

Re: Anyway to use bash scripts in execution steps

My full command:

#Get Project id for 'Technical Infrastructure Old'
ksc_comment "Project type id: [REQ.P.KNTA_PROJECT_TYPE]"
ksc_comment "Project type name: [REQ.VP.KNTA_PROJECT_TYPE]"
if [ "[REQ.VP.KNTA_PROJECT_TYPE]" = "Technical Infrastructure" ] ;
then
  ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
  ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
fi
ksc_comment "ok"

 

In my command, condition parameter is blank.

 

Erik Cole
Acclaimed Contributor.

Re: Anyway to use bash scripts in execution steps

It's likely trying to parse your bash conditional

 

[if [ "Technical Infrastructure Old" = "Technical Infrastructure" ]]

 

as a token, and coming up confused.

 

You might want to just encapsulate the logic in a shell script or a db function and just call it using the [REQ.VP.KNTA_PROJECT_TYPE] as input.

TurboMan
Honored Contributor.

Re: Anyway to use bash scripts in execution steps

Thanks All,

 

I think, there is no way of using bash scripts in execution steps.

Anyhow, I managed to made it work through "condition" parameter as follows

 

condition :  

'[REQ.VP.KNTA_PROJECT_TYPE]' = 'Technical Infrastructure'

in Steps:

#Get Project id for 'Technical Infrastructure Old'
ksc_comment "Project type id: [REQ.P.KNTA_PROJECT_TYPE]"
ksc_comment "Project type name: [REQ.VP.KNTA_PROJECT_TYPE]"
ksc_itg_run_sql QUERY_STRING="SELECT project_type_id  FROM pm_project_types WHERE project_type_name='Technical Infrastructure Old'"
ksc_store REQ.P.KNTA_PROJECT_TYPE="[SQL_OUTPUT]", "Technical Infrastructure Old"
ksc_comment "ok"

 

Even though this solves my problem, I am not happy with the solution.

I prefer script-style steps.

I attached an image.

 

Regards

T.M.

dlinetsk
Super Contributor.

Re: Anyway to use bash scripts in execution steps

as I said, you can use IF statements within command scopes - for example ksc_connect_dest_server. Once the command reaches the server, your IF statements will be executed no problem. I just set it up on my environment. For out of command scope Condition parameter should be used.
TurboMan
Honored Contributor.

Re: Anyway to use bash scripts in execution steps

But, it didn't work.

Anyway, I applied you suggestion it worked.

You've got my kudos. 

 

Thanks

Jim Esler
Acclaimed Contributor.

Re: Anyway to use bash scripts in execution steps

PPM does not understand Bash. In order to execute a Bash command you need to log in to a server or use the ksc_local_exec special command. PPM will then pass the commands to Bash for execution. Note that conditional statements like if..fi need to be placed on a single command line. Bash conditional statements cannot be used to control execution of PPM special commands, though. The method you ended up using, placing the condition on the command step, is the best method for what you are doing here.