microsoft / azure-pipelines-agent

Azure Pipelines Agent 🚀
MIT License
1.73k stars 869 forks source link

How to run a simpler Power Shell Script on all Build Agents i have in Single Agent Pool #1708

Closed IbrahimUmar closed 6 years ago

IbrahimUmar commented 6 years ago

Have you tried trouble shooting?

Trouble shooting doc

Agent Version and Platform

Version of your agent? 2.102.0/2.100.1/...

OS of the machine running the agent? OSX/Windows/Linux/...

VSTS Type and Version

VisualStudio.com or On-Prem TFS?

If On-Prem TFS, which release? 2015 RTM/QU1/QU2/...

If VisualStudio.com, what is your account name? http://account.visualstudio.com

What's not working?

Please include error messages and screenshots.

Agent and Worker's Diagnostic Logs

Logs are located in the agent's _diag folder. The agent logs are prefixed with Agent_ and the worker logs are prefixed with Worker_. All sensitive information should already be masked out, please double check before pasting here.

Related Repositories

Please ensure you are logging issues to the correct repository in order to get the best support.

If you are hitting a generic issue about VSTS/TFS, please report it to the Developer Community

TingluoHuang commented 6 years ago

@IbrahimUmar what's your scenario? you want to get all machine name from an agent pool and run remote powershell? or you want your build/release job always run some script for policy needed?

IbrahimUmar commented 6 years ago

I have implemented Parallelism/Execution of tests on multiple agents in Visual Studio Test V2 through agent phases. I want to run a powershell script on all Agent Machines in single agent pool before execution of test cases in parallel in agent phases. Is there any workaround.?

TingluoHuang commented 6 years ago

@IbrahimUmar what if you add a powershell task to your build definition, will it runs on all agents?

IbrahimUmar commented 6 years ago

This is what i want. Is this possible? I dont want to mention machine name. it should pick up all agents by itself.

TingluoHuang commented 6 years ago

image i assume if the number of agent match the amount of agents you have in your pool, then it should work.

IbrahimUmar commented 6 years ago

This is phase description. VsTEST is the that will be executed as 1st option. BUT I want to add another task which should executed before test run , POWERSHELL script which delete all DBs on these agents before execution of test runs.

TingluoHuang commented 6 years ago

Why don't you do that as part of your TestInitialize() in code?

IbrahimUmar commented 6 years ago

pshelltask

I have added the PowerShell task before the VsTest Task in the same Agent Phase and it showing this error:

Error: Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)" Retry in 10 seconds. Attempts left: 5 Error:

TingluoHuang commented 6 years ago

@IbrahimUmar is this error coming from your script?

IbrahimUmar commented 6 years ago

My Script basically deleting temp DBs before execution of test runs (Through VsTest V2) on all Agents in that pool. This error showing when the powershell script executed.

TingluoHuang commented 6 years ago

@IbrahimUmar then i guess you need to fix your script, back to my other point, why not do this cleanup as part of your test code, during TestInitialize()?

IbrahimUmar commented 6 years ago

Just correct me where i am wrong: I have created a single pool with 10 Machines agents. I want to test the Unified Build Agent Functionality. What i have done, created a Build definition for the compilation of code: My Code gets compiled and published successfully. then it calls a reelase definition and It starts running Parallelsim test cases on multiple agents option selected. What is the requirement of an agent? Does it required Visual Studio and SQL installed on all machines? or one of the machines in the line of 10 agents? I am confused about it. PLEASE CORRECT ME WHERE I AM WRONG.

TingluoHuang commented 6 years ago

@IbrahimUmar you need to install required software on all agents (VS + SQL in your case). the Parallel test run should break down all your test cases into small chunk and run each chunk all one of the 10 agents.

Ex: you project contains 100 testcases. when you queue the parallel test release definition, it should runs on 10 agents, and each agent runs 10 test case.

IbrahimUmar commented 6 years ago

I heared from someone that Unified Build Agent install required packages itself then start build and executes tests. is it?

TingluoHuang commented 6 years ago

what required packages?

IbrahimUmar commented 6 years ago

Visual Studio and SQL or whatever it required to run , it automatically picks up?#

TingluoHuang commented 6 years ago

It won't install them for you, you need to install any software or tool you need in your build/release process.

TingluoHuang commented 6 years ago

the agent or the task is able to find those software if it installed.

IbrahimUmar commented 6 years ago

Alright.

We basically have separated Agent Machines and Build Machines in our current systems. Agent/Build Machine: Visual Studio and Build Agent is install and we just compile our code and publish. Test Machines: These are machines which only run test cases of different kind and We have dedicated their names , like test1,test2,test3,test4 will be used for unit tests. test6,test18,test19 will be used for integration tests and so on . On these test machines we have only sql installed. If we will use Unified Agent concept , You mean we have to keep all machines at same level?? means VS and SQL required to be installed on alll machines (Agents) in the agent pool?

TingluoHuang commented 6 years ago

how do you control your integration tests only runs on Test6/18/19 agent? so they won't landed on machine doesn't have the dependencies.

IbrahimUmar commented 6 years ago

I couldnt get you. please explain this. thanks!

TingluoHuang commented 6 years ago

base on the parallelism config, it will try run on all agents within the pool that meet the demands. you don't have to install VS and SQL to all machines in the pool as long as you can make sure your build/release landed on the agent machine has the right dependencies. did you try use demand to control this? image

IbrahimUmar commented 6 years ago

Never used this feature. What i understands that you never need to install VS or SQL on Any agent in the agent pool. Just mention this in demand portion and it will automatically install what packages you need to run. is it? Can you please explain this more.

IbrahimUmar commented 6 years ago

My Agent pool looks like:

  1. Build/Agent Machine . Installed VS and SQL
  2. Test Machine , SQL installed (5 Machines)

These 6 machines are under single agent pool. How does agent pool works? Should i assign one agent pool in build process the another in release process where multiple test runs will execute?# or need to use the same pool and let the agent pool choose hwo to work with?#

How agent pool works in this scenario where you need to pick up multiple machines ?

TingluoHuang commented 6 years ago

https://docs.microsoft.com/en-us/vsts/pipelines/agents/pools-queues?view=vsts

IbrahimUmar commented 6 years ago

It IS VERY USEFUL. Thanks

In Demands, i want to add that test should run only that machine where SQL Express is installed. How should i mention this there:

MS SQL Exists InstallSQL Exists

or something else.

Moreover, demands only detect particular installation on agent machine or it get the required package install itself as well. Kindly share your thoughts.

TingluoHuang commented 6 years ago

https://docs.microsoft.com/en-us/vsts/pipelines/agents/agents?view=vsts#capabilities

IbrahimUmar commented 6 years ago

Kindly check with these errors after enabling demands:

No agent found in pool UnifiedAgent which satisfies the specified demands: InstallSQL SqlPackage DotNetFramework Agent.Version -gtVersion 1.102

TingluoHuang commented 6 years ago

does the agent you trying to use has those demands? image

IbrahimUmar commented 6 years ago

This is Good , it worked.

There is an issue now:

When i select in VsTest V2 that these tests should be run on Multiple Agents and given the number of agents in the below Box. It creates two tabs: Agent 1 of 2 Step one Step two Agent 2 of two Step one Step two

Why the system using only single Build Agent/Machine as two agents? In above scenario , single machine is being used in both cases, WHY? Kindly share what i am missing.

TingluoHuang commented 6 years ago

how many agents do you have on that machine?

IbrahimUmar commented 6 years ago

Single Agent per machine and it is showing on agent pool tab.

IbrahimUmar commented 6 years ago

I am considering single machine as agent. It also means i have installed a single agent per machine.

TingluoHuang commented 6 years ago

i am going to close this issue as it is not an actual agent issue and the question has be answered.