Azure DevOps ssh script file task - azure-devops

I'm just wondering if it's possible to use a script file in the SSH task in the Releases that will be populated with the environment variables from azure.
Script:
TEST=$(test)
I saved this script as an artifact, successfully download it, and select this script in the SSH task as a file, but the problem is the environment variables is not unwrapped, does someone have some approach?
If I put this same script as an inline script, then it's working. But if I chose script file then not.
I want to have this script in the git repo, so I can easily edit the script.
Does someone have this working?

I'm just wondering if it's possible to use a script file in the SSH task in the Releases that will be populated with the environment variables from azure
I am afraid there is no such out of way to use a script file in the SSH task to populated with the environment variables from azure.
As workaround, we could use the task Replace Tokens to update the value in the script file:
The format of variable in .sh file is #{TestVar}#.
Hope this helps.

Related

How to read release pipeline variable and use as environment variable in Azure DevOps in Azure CLI task?

I am using one powershell task and one Azure Cli task in release pipeline of Azure DevOps.
I have some release pipeline's variables. I want to read those variables as they will be required by my script in above two tasks. I used powershell core in Azure cli task
I tried to read them in the inline script directly as $(variableName) or $env:variableName but none of the above worked.
I tried to set read the variable in Environment variables option in the task and then use in the inline scripts using $env:variableName but it also didn't work. On printing the variableName in the script using Write-Host, the value I got is $(valueName) instead of the correct value.
How to read those variables inside these scripts?
The pipeline variables can be reference in the Azure CLI inline script by using the syntax $(variableName). I tested by adding the following in a script
write-host "The variable value: $(variableName)"

Can I access Azure App Configuration inside a script called in a pipeline task?

Using Azure App Configuration I can make the variables available to the entire pipeline. However, if the following task is running a PowerShell script, called Script.ps1. Are the configs vars going to be available in that script or do I have to pass them as input to the script?
The key-values that are fetched from App Configuration are set as pipeline variables, which are accessible as environment variables. To use environment variables in your PowerShell script file you can refer to the following.
Use environment variables in PowerShell script file:
Use PowerShell task in pipeline:
The result in the pipeline:

Azure DevOps: How can I run powershell on onPrem servers after deployment of all IIS Sites

How can I run a powershell script after all stages have completed deployment? I have currently selected a deployment group job but am not 100% sure if this is what I need. I have included the script as part of the solution that is being deployed so that it will be available on all machines. Based on what I can find in the UI there seem to be 2 tasks that could work.
The first option would be to execute the task "Powershell Script" but it is asking for a path in the drop directory. The problem with this is that the file that I am interested in is in a zip file and there does not seem to be a way to specify a file in the zip file.
The other task I see is "PowerShell on Target Machines" and then it asks for a list of target machines. I am not sure what needs to be entered here as I want to run the powershell script on the current machine in the deploy group. It seems like this task was intended to run powershell scripts from the deployment machine to another remote machine. As a result this option does not seem like it fits my use case.
From looking the answers that I have come across talk about how to do this as part of an Azure site using something called "Kudu" (not relevant) or don't answer my other questions related to these tasks or seem like they are out of date.
A deployment group job will run on all of the servers specified in that deployment group. Based on what you have indicated, it sounds like that is what you are looking for.
Since you indicated that the file in question is a zip, you are actually going to need to use 2 separate tasks.
Extract Files - use this to extract the zip file so that you can execute the script
Powershell script - use this to execute the script. You can set the working directory for the script to execute in if necessary (under advanced options). Also remember that you don't have to use the file/folder selector 'helper' as it wont work in your case if the file is inside a zip. This is just used to populate the text box which you can manually do starting with the $(System.DefaultWorkingDirectory) variable and adding the necessary path of the script.

Read Octopus variables

I am new to octopus and have a bunch of steps. For each steps we have "Machine Roles".
As part of the steps I have a script tasks/step and I wish to access the roles assigned to this step in the (powershell) script. How can I achieve this.
I tried a few things, i.e. Octopus.Machine.Roles, Octopus.Tentacle.CurrentDeployment.TargetedRoles in the (powershell) script. But does not see anything.
As found in this example, if you have a variable in Octopus, you can access it using the variable name, prefixed with a $ in PowerShell, so for a variable TestUrl use:
$TestUrl
For Octopus Parameters, you use the following:
$OctopusParameters['Octopus.Machine.Roles']
This should give you access to all the system variables.

Run local executable file on remote servers with Capistrano

I have a pretty long .sh file in my Capistrano tools directory that is intended to be executed on servers, not locally. Is there a simple way to execute this file on servers inside a Capistrano task without manually copying it on each server?
Assuming that the script is in your repository, you can create a custom task which allows you to do exactly that. Something like:
namespace :deploy do
desc 'Run custom command'
task :run_custom_command do
on roles(:app) do
# Your restart mechanism here, for example:
execute release_path.join('tools/command.sh')
end
end
before :publishing, :run_custom_command
end