How to take the config.XML field value based on property file value in shell script? [closed]

I have an XML file called config.xml

<builders> <hudson.tasks.Shell> <command>$RA_CHEKOUT_SHELL_COMMAND</command> </hudson.tasks.Shell> </builders>

Here is my property file content

build.prop

This is to check out the job from Jenkins. here we are going to perform checkout operation.

Shell script

Here I am reading the property file line by line and assign the property file values into a variable and used the value in config.xml file field.

file="/var/lib/jenkins/workspace/Env-inject-example2/build.prop"
counter=1
while IFS= read line
do # display $line echo "Text read from file: $line" counter=`expr $counter + 1` name=$(cat "$file") echo $name echo "Change values in config.xml..."
done <"$file"
cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<config> <builders> <hudson.tasks.Shell> <command>$name</command> </hudson.tasks.Shell> </builders>
</config>
EOF
echo "Done."

Note: Now I have used the config.xml within the shell script to change the field value but I want to use the shell variable outside config.xml file.How should I represent the path and How should I inject the values to the config.xml file.

5

1 Answer

sed "s@PatternThatShouldBeReplaced@$name" /Path/To/config.xml

Note: sed seperator normally is / but I suggest @ in this case for allowing the variable to include / without escaping

0

You Might Also Like