echo "--- Starting Parameterized Build Step ---"
echo "Hello, $GREETING_NAME!"
echo "Deploying to the $ENVIRONMENT environment."
## Create project structure if not exists and read the version from the file
mkdir -p my-app
echo "Version 1.0" > my-app/version.txt
APP_VERSION=$(cat my-app/version.txt)
echo "Application version is: $APP_VERSION"
echo "--- Parameterized Build Step Finished ---"
プラグインの横にあるチェックボックスをオンにし、Install without restart をクリックします。
インストールが完了するまで待ちます。
失敗をシミュレートするためのスクリプトの変更
次に、特定の条件で失敗するようにスクリプトを変更します。
parameterized-script-job の Configure ページに移動します。
Execute shell コマンドボックスで、スクリプトを以下に置き換えます。
echo "Deploying to the $ENVIRONMENT environment."
if [ "$ENVIRONMENT" = "PROD" ]; then
echo "Error: Production deployment is not allowed!"
exit 1
fi
echo "Deployment to $ENVIRONMENT was successful."
Deploying to the PROD environment.
+ [ PROD = PROD ]
+ echo Error: Production deployment is not allowed!
Error: Production deployment is not allowed!
+ exit 1
Build step 'Execute shell' marked build as failure
Performing Post build task...
Match found for :Error: : True
Logical operation result is TRUE
Running script : echo "FAILURE DETECTED! Sending notification..."
[parameterized-script-job] $ /bin/sh -xe /tmp/jenkins14011006354379294736.sh
+ echo FAILURE DETECTED! Sending notification...
FAILURE DETECTED! Sending notification...
POST BUILD TASK : SUCCESS
END OF POST BUILD TASK : 0
Finished: FAILURE