I am trying to do web job creation, if not exist.
for single webapp this line of command worked.
az webapp deployment source config-zip --resource-group "rg1" --name "webapp1" --src "pathfile.zip"
Zip file structure was created as described as in
https://github.com/projectkudu/kudu/wiki/WebJobs.
I can see the webjob created, but when I am putting it in the loop I am getting error.
here is the code I have so far.
# Resource group name........
resourceGroup="rg1"
# Path to the zip file containing the web job
zipFilePath="zipfilepath/file.zip"
# Web job name
webJobName="webjob1"
# Get a list of all web apps within the resource group
webAppNames=$(az webapp list --resource-group $resourceGroup --query "[].name" -o tsv)
# Loop over each web app name
for webAppName in $webAppNames; do
# Check if the web job already exists in the web app
if az webapp webjob triggered list --resource-group $resourceGroup --name $webAppName --query "[?name=='$webJobName']" -o tsv | grep -q "$webJobName"; then
echo "Web job '$webJobName' already exists in web app '$webAppName'. Skipping deployment."
else
echo "Deploying web job '$webJobName' to web app: $webAppName"
az webapp deployment source config-zip --resource-group $resourceGroup --name $webAppName --src $zipFilePath
fi
done
Error
At line:14 char:4
+ for webAppName in "${webAppNames[@]}"; do
+ ~ Missing opening '(' after keyword 'for'. At line:14 char:42
+ for webAppName in "${webAppNames[@]}"; do
+ ~ Missing statement body in do loop.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword
2
Answers
Before running the script, I found an error when pasting your code into my PowerShell environment.
As the provided script by you is completely a CLI code format, it is properly executing in Cloud Shell environment as shown below.
To make it work as expected when you execute in Windows PowerShell ISE environment, run the below modified script with PowerShell syntax.
Here I have used a
foreach
loop to loop over all the listed webapps and also used anif
loop to check the existence.i tried with the same as you share , but it not display the webjob in the Azure web Job Section