yii - Jenkins - parametrise .php file -


i configuring jenkins in order make build project. checks out source code, installs required libs etc..

my application configuration stored in params.php file (yii 1.x style), looks following way:

return array(     'dbhost' => 'dbhostvalueplaceholder',     'dbpasssword' => 'dbpasswordvalueplaceholder',     /* other values go here */ ); 

obviously need replace dbpasswordvalueplaceholder password set when starting parametrised build.

current solution i've found running shell command:

sed -i s/dbpasswordvalueplaceholder/$db_password/g $workspace/protected/config/params.php 

where $db_password corresponding variable.

this solution work simple strings, password may a1@2";$&^*&-=+/*-:'/.,,,,,,,,^^^^^ - in case sed fails because of unescaped characters.

i have searched different jenkins plugins, there plugins work other formats .xml etc, , neither works .php files.

i need avoid moving config values out of .php file other format.

is there way replace described tokens in .php file build parameters values ?

update

as @stanjer recommended, have tried set param value to:

a1@2";$&^*&-=+/*-:\'/.,,,,,,,,^^^^^ 

so, in case, following code in php right, valid:

'universalpassword' => 'a1@2";$&^*&-=+/*-:\'/.,,,,,,,,^^^^^', 

it not help, here output:

[build.int] $ /bin/sh -xe /tmp/hudson642312569695847678.sh + sed -i s/defaultuniversalpassword/a1@2";$&^*&-=+/*-:\'/.,,,,,,,,^^^^^/g /var/www/build.int/protected/config/params.php sed: -e expression #1, char 43: unknown option `s' build step 'execute shell' marked build failure finished: failure 

thanks updated question.

in case should show it's escaped providing $'string'.

so command like:

$ sed s#dbpasswordvalueplaceholder#$'"a1@2";$&^*&-=+/*-:\'/.,,,^^^"'#g test.php

and output be:

<?php  return array(     'dbhost' => 'dbhostvalueplaceholder',     'dbpassword' => '"a1@2";$dbpasswordvalueplaceholder^*dbpasswordvalueplaceholder-=+/*-:'/.,,,,,,,,^^^^^"',     /* other values go here */ );  ?> 

if using variable:

export newpass=$'"a1@2";$&^*&-=+/*-:\'/.,,,^^^"'

sed "s#dbpasswordvalueplaceholder#$newpass#g" test.php


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -