1

Maybe the title of this question is not totally accurate so I will demonstrate it via code:

We have in Linux something like the code below:

sudo update-alternatives --set php /usr/bin/php$(phpVersion)

Which then gives you the ability to use php as a command like below:

php artisan migrate --seed

Recently I need something like this on windows,

I have added that address to Environment Variables so it is a tested solution which did not answer and should directly be done via cmd

It's needed for a DevOps CMD Task

Mehdi Amenein
  • 937
  • 9
  • 23
  • 1
    See my answer here for a sudo like command https://stackoverflow.com/questions/54658352/passing-quoted-arguments-from-batch-file-to-powershell-start-self-elevation/54680601#54680601 – Noodles Feb 25 '19 at 20:38
  • Thank you for your message, That's also an interesting concept, What I understood from your code as it is some sort of overriding via a manifest, Right? Unfortunately that is a Unix thing and here I seeking for a translation from Linux to Windows Command. I have a solution with Batch file for it but first want to see if anyone else has a more clean way to do so or not. (Cause batch is not supported in Windows Server 2012 R2) – Mehdi Amenein Feb 26 '19 at 10:13
  • There are two ways to elevate, Embed a manifest into an exe file or right click and choose Run As Administrator. – Noodles Feb 26 '19 at 19:20
  • Here is it's sister one - this is for starting non console program elevated. https://pastebin.com/sECS6Pyw. There is no sudo command in Windows. You have to make your own. – Noodles Feb 26 '19 at 20:47

1 Answers1

1

Ok, I have fixed that Issue another way, the reason for that issue was mixing up Deploy and Build Stages. In other word, Building tasks could be done with Ubuntu VSTS Agent and Windows was required for deploy tasks.

But I think maybe giving a solution for the case can be helpful for others:

This case in windows can be solved with defining Environment Variables via cmd code. Please run Command Prompt as administrator:

setx -m php "{PHP_ADDRESS_ON_MACHINE}"

So this way should solve any similar issue to mine with any other thing than php like mysql, mongodb, appcmd or...

If you have any issue on running cmd as administrator you can do 2 things:

1- create a private VSTS agent and define your desire thing as a Enviroment variable on it

2- Take look at the case below, it is really helpful

Run Powershell or Command Prompt as administrator during Visual Studio Team Services build

I hope this can help someone else here as well

Mehdi Amenein
  • 937
  • 9
  • 23