
config.xmlというXMLファイルがあります
<builders>
<hudson.tasks.Shell>
<command>$RA_CHEKOUT_SHELL_COMMAND</command>
</hudson.tasks.Shell>
</builders>
これが私のプロパティファイルの内容です
ビルドプロパティ
これは、Jenkins からジョブをチェックアウトすることです。ここでは、チェックアウト操作を実行します。
シェルスクリプト
ここでは、プロパティ ファイルを行ごとに読み取り、プロパティ ファイルの値を変数に割り当て、config.xml ファイル フィールドの値を使用します。
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."
注記:現在、シェル スクリプト内で config.xml を使用してフィールド値を変更していますが、config.xml ファイル外でシェル変数を使用したいと考えています。パスをどのように表現し、config.xml ファイルに値をどのように挿入すればよいでしょうか。
答え1
sed "s@PatternThatShouldBeReplaced@$name" /Path/To/config.xml
注: sedのセパレータは通常/ですが、この場合は変数に/をエスケープせずに含められるように@を使用することをお勧めします。