I'm building a Jenkins pipeline that should allow me to send remote commands to a Windows Machine.
For example, I want to move a file from one place to another. My pipeline code looks like this:
az vm run-command invoke --command-id RunPowerShellScript --name VM_name -g test_g --scripts " Copy-Item -Path C:\BuildFiles\File.xml -Destination C:\Program Files (x86)\File\File Path\File version\"
From PowerShell, it works fine. But when I'm trying to run it from Jenkins as a bat script(I'm running Jenkins on windows) and adding the syntax bat'' or bat"" will give me syntax errors or invalidate my scripts.
Any way that I can make the script work?
Issue
You should not be using the bat function but rather the powershell function. Your code should look like the following.
Code
powershell label: '', script: '''
az vm run-command invoke
--command-id RunPowerShellScript
--name VM_name
-g test_g
--scripts "
Copy-Item
-Path C:\\BuildFiles\\File.xml
-Destination C:\\Program Files (x86)\\File\\File Path\\File version\\"
'''
Related
I create new runbook by ansible-playbook like that
name: Connect azure account
command: pwsh -Command "(Connect-AzAccount -Identity).context"
name: Create runbook
command: pwsh -Command "New-AzAutomationRunbook -AutomationAccountName 'Testing' -Name 'Runbook02' -ResourceGroupName 'hoadtn_ansible_rg' -Type Python3"g
But when I run , it show error
how to resolve this error ?
thanks
For the above error please make sure that you have updated Ansible version which is 2.9 or above.
Then run the command az login once successfully run the command then run the following command to create runbook in your azure automation .
We have tried the same and works fine :
For more information please refer the below links:-
Ansible Installation guide
SO THREAD: Ansible install all required Azure modules
I am attempting to install an artifact through an azure VM - I have remoted into the VM through the powershell on azure and am running the following command:
Enter-AzVm -Name <MyVM> -ResourceGroupName <MyResourceGroup> -Credential (get-credential)
When I'm connected onto the VM I'm attempting this download command which works on my local machine:
az artifacts universal download --organization <MyOrganization> --project=<MyProject> --scope project --feed <MyFeed> --name <MyFirstPackage> --version 0.0.1 --path .
This is the error I'm getting while attempting that download :
The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program
I tried to run the command to install CLI on the VM which runs, but after that installation run I cannot see az --version with the same error. Any help would be appreciated.
I have never used Enter-AzVm to remote into the VM to install Azure CLI, seems the Enter-AzVm just works in Azure Cloud Shell(not sure).
I installed the Azure CLI successfully via Invoke-AzVMRunCommand command in a Windows VM, when I test az --version in cloud shell after remoting into the VM with Enter-AzVm, it works fine, you could follow the steps below.
1.Save the command below in local as a installcli.ps1 file.
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
2.Run the command below in local.
Invoke-AzVMRunCommand -ResourceGroupName 'groupname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'C:\Users\joyw\Desktop\installcli.ps1'
3.After the command completed, navigate to the cloud shell, use Enter-AzVm to remote into the VM, then run az --version, it works fine.
Actually, if the steps above not work for you, you can also store the azure cli command as a .ps1 file like step 1, then use Invoke-AzVMRunCommand to run it, it will work.
I have a windows Azure VM and need to execute “%windir%\system32\sysprep” and then execute “sysprep /generalize” both from admin mode from my local machine through Powershell. How can I do that ?
For your requirements, as I know you can use a PowerShell script to achieve it. First, you can take a look at the Sysprep, it can be run in a PowerShell command C:\WINDOWS\system32\sysprep\sysprep.exe /generalize /shutdown /oobe. Put this command inside a script, then you can use two ways to run this script in the VM from your local machine. One is that use the Invoke command.
In Azure CLI:
az vm run-command invoke --command-id RunPowerShellScript -g group_name -n vm_name --scripts #script.ps1
In PowerShell:
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1'
Another is that use the VM extension. It's a little complex. You can take a look at the Azure PowerShell command Set-AzVMCustomScriptExtension.
Output after running:-
Value[0] :
Code : ComponentStatus/StdOut/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Value[1] :
Code : ComponentStatus/StdErr/succeeded
Level : Info
DisplayStatus : Provisioning succeeded
Message :
Status : Succeeded
Capacity : 0
Count : 0
I could't make sysprep work with Invoke-AzVMRunCommand, It run with succeeded status, but the VM was not shutdown.
Finally found https://developercommunity.visualstudio.com/t/devops-sysprep-public-agents/1375989 and it make sense.
So just use Invoke-AzVMRunCommand to run sysprep won't work, I am thinking to reset a local admin user password and run the process as local admin might be a workaround.
Thanks in advance, I'm trying to deploy custom script extension from Azure CLI from Cloud Shell. But getting error of expecting value. I'm using SAS key to download the PS file. I've tried to use every possible way of adding Protected settings, and Pointing to json but it still gives me an error.
With the below Azure CLI Command
az vm extension set --name CustomScriptExtension --publisher Microsoft.Compute --settings '{"fileUris": ["https://archivewsldisks.blob.core.windows.net/container/newfolder.ps1?sp=rcwd&st=2019-06-20T06:27:08Z&se=2019-07-31T14:27:08Z&spr=https&sv=2018-03-28&sig=oRzT7soN%2B2jvL6CxtYN%2B435B7XJYf05TgyPya2VR43Y%3D&sr=b"], "commandToExecute":powershell -ExecutionPolicy Unrestricted -File newfolder.ps1}' --resource-group "vm-test-group" --vm-name "testvm1" --version 1.9
error image
For your issue, it's just a mistake. The parameter --setting expect a JSON value and the command you execute misses the quotation marks in it. Just change the value of the parameter --setting like this:
--settings '{"fileUris": ["https://archivewsldisks.blob.core.windows.net/container/newfolder.ps1?sp=rcwd&st=2019-06-20T06:27:08Z&se=2019-07-31T14:27:08Z&spr=https&sv=2018-03-28&sig=oRzT7soN%2B2jvL6CxtYN%2B435B7XJYf05TgyPya2VR43Y%3D&sr=b"], "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File newfolder.ps1"}'
I am trying to configure a Pipeline with Jenkins and deploying it to Azure. I am at the last step of a tutorial:
https://learn.microsoft.com/en-us/azure/jenkins/tutorial-jenkins-deploy-web-app-azure-app-service
This last step is as follows, i have to enter this in the Azure CLI:
az group create --name yourWebAppAzureResourceGroupName --location region
az appservice plan create --name appServicePlanName --resource-group rgname --is-linux
az webapp create --name webAppName --resource-group rgName --plan appServicePlanName --runtime "java|1.8|Tomcat|8.5"
The last command gives me the error:
'1.8' is not recognized as an internal or external command,
operable program or batch file.
So I thought maybe Tomcat is not installed on my Azure VM, which is a Linux machine. So I used the next tutorial to install Tomcat:
https://www.howtoforge.com/tutorial/how-to-install-apache-tomcat-8-5-on-ubuntu-16-04/
After this I tried to do the --runtime command again, but I still get the same error. I have no idea how to fix this. I hope someone can help me with this problem.
I tried to check the webapp list-runtimes and I get this list:
"java|1.8|Tomcat|8.5" is in here. I've tried all of the versions, but it did not work.
EDIT: It works in the Azure Cloud Shell, but then there is another error:
Linux Runtime 'java|1.8|Tomcat|8.5' is not supported.Please invoke 'list-runtimes' to cross check
I have tried all the runtime versions, but still this error. I have also tried it with double quotes
I bet you solved your problem already, but in case others find this and are using PowerShell to run Azure CLI commands. This is what worked for me.
The problem is in how PowerShell interprets the pipe, '|', character inside the --runtime parameter, when evaluating the whole line.
Add the --% to be beginning of the command to turn off PowerShell evaluation of expressions, as suggested in the code block here.
Note: this will also stop PowerShell from evaluating any variables inside the command. What you can do is move the --runtime to the end of the line to get around this problem, e.g. like this
az webapp create -g $rg -p $appPlanName -n $appName --deployment-local-git --% --runtime "DOTNETCORE|3.0"
ok, i got it, that list is for windows webapp, not linux. for linux use:
az webapp list-runtimes --linux
so working solution:
az webapp create --name yourWebAppName --resource-group yourWebAppAzureResourceGroupName --plan yourLinuxAppServicePlanName --runtime "TOMCAT|8.5-jre8"