Skip to content

Commit

Permalink
Upd dotnet6 agent mar2023 (#4191)
Browse files Browse the repository at this point in the history
* Catch updating exception (#4082)

* Node16 version updated to 16.17.1" (#4084)

* Bump ubuntu image version to 20.04 (#4079)

* Prevent creating host container network (#3788)

* Prevent creating host container network

* Remove redundant empty lines

* Fix invalid knob value fetching

* Update ContainerOperationProvider.cs

Co-authored-by: Denis Rumyantsev <[email protected]>
Co-authored-by: Kirill Ivlev <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>

* Allow env.sh to accept additional env var names (#3339)

The hard-coded list is not necessarily enough. This allows the caller
to specify additional environment variables to write to .env.

Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Kirill Ivlev <[email protected]>

* Revert "Fix execution of scripts in variables (#4016)" (#4088)

This reverts commit af5328b.

* Add Ubuntu 18.04 (#3943)

Co-authored-by: Kirill Ivlev <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>

* Make agent update list of systems supporting .NET 6 periodically (#4081)

* implemented logic to fetch net6.json from server every hour

* added await keyword

* Moved logic to set warning from ExecutionContext to JobRunner since InitializeJob method is not async

* fixed issue with condition in Equals method of OperatingSystem class

* small refactoring

* net6.json must be read only if it was not fetched from server

* refactored code of method "GetNet6SupportedSystems"

* restored field net6SupportedSystems to reduce IO oprations and cover case when agent started but net6.json is not older than 1 hour

Co-authored-by: Kirill Ivlev <[email protected]>

* Retries to lock Services database (#4085)

* retries to lock database

* Decrease timeout + Add retry message

Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>

* Fixed name of DockerAdditionalNetworkOptions Knob (#3888)

Co-authored-by: Konstantin Tyukalov <[email protected]>

* Format agent source code (#4101)

* Run dotnet format

* Remove extra semicolons

* Fix SonarQube's "'Any()' should be used to test for emptiness" / Code Smell (#3404)

* Add script to predict v2->v3 upgrade compatibility (#4092)

* Add script to predict v2->v3 upgrade compatibility

* Fix typo

* Fixed another typo: frpom

Co-authored-by: Kirill Ivlev <[email protected]>

* Added strict boolean knob values (#4103)

* Add ConvertToBooleanStrict

* Add AsBooleanStrict for agent knobs

* update build-job (#4110)

* update build-job
- added UseDotNet task for linux os

* Switch EsrpCodeSigning from V1 to V2
returned back UseDotNet task condition

* Set UseDotNet version to 6 on osx

* added dotnet 3.1.x before unit tests on win x86

* fix dotnet host search (#4124)

* fix dotnet host search
- added performMultiLevelLookup

* Added runtime to unitTests step

* Changed patch version in semver of runtime

* remove sdk and runtime from unitTests script

* Fixed problem with .NET Core 3.1 installation

* Added UseDotNet task in functionalTests

Co-authored-by: Roman Shchukin <[email protected]>

* Add option to skip rhel6 in pipeline and ci (#4121)

* skipRhelRelease parameter added

* skipRhelRelease parameter fixed

* releaseRhelOnly parameter added

* Logic of removing not filling lines from releaseNote

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Fix pipeline with test releaseNote job

* Removed test logs

* Added clear empty lines logic

* Commented code for test. Test changes in pipeline

* Removed test changes

* skipRhelRelease parametr added to ci pipeline

* Update dotnet to 3.1.32 (#4112)

* DockerLogin retries (#4100)

* DockerLogin retries
- added changes from PR #3840
- fixed incorrect variables

* DockerLogin retries
- added step UseDotNet@2

* DockerLogin retries
- added linux to UseDotNet task

* Docker Login retries
Implement retry into DockerLogin method

* Implement feature flag for docker login retries

* revert build-job back

* Added retry for docker start

* fix delay

* update knob description

* Update agent Docker methods
- reworked Docker methods with retries behavior
- changed InvokeWithRetryIfNonZero on to incapsulated logic method

* - renamed local variable as is in ADO

* Added docker retry behavior to docker version method

Co-authored-by: Your Name <[email protected]>
Co-authored-by: Kirill Ivlev <[email protected]>
Co-authored-by: Merlyn Oppenheim <[email protected]>

* Add the exact operation system version and environment to the telemetry (#4104)

* Update TaskRunner.cs

* Update build-job.yml

* Added new variables to telemetry AgentName, MachineName, IsSelfHosted

Co-authored-by: Kirill Ivlev <[email protected]>

* Mingit version upgraded to 2.39.1 (#4126)

* Fix agent lint errors (#4117)

* Fix CA2000 error with secrets masker

* Fix CA1711 for ServiceBootFlag

* Fix CA2000 for JobRunner

* Resolve CA2000 in StepHost

* Resolve CA2000 in Windows service

* Resolve CA2000 for WorkerCommandManager

* Resove CA2000 for CodeCoverageCommands

* Remove unused namespaces

* Add fixture for SecretMasker tests

* Change Fixtures -> Disposable

* Use dispose pattern to fix errors

* Formatting

* Revert "Allow env.sh to accept additional env var names (#3339)" (#4143)

This reverts commit 27e3d4e.

* Bump azure pipelines task lib to 4.2.0 (#4155)

* Add warning for deprecated runners (#4162)

* Add warning for deprecated runners

* Update strings.json

* fix typo

* Update NodeHandler.cs

* FEATURE 2019014 - Gather telemetry on Agent Azure & Docker Container usage (#4166)

* FEATURE 2019014 - Gather telemetry on Agent Azure & Docker Container usage

* Re-write try-catch

* Update TaskRunner.cs

* cleanup

* Distinguish AzureInstanceMetadata detection to a separate class

---------

Co-authored-by: Kirill Ivlev <[email protected]>

* Added legacy lib source for support on Ubuntu 22.04 (#4161)

* Moved logic to drain queues after each task under knob "AGENT_DRAIN_QUEUES_AFTER_TASK" (#4176)

* Added knob "DrainQueuesAfterTask" with default "false"

* move logic to drain queues behind knob DrainQueuesAfterTask

* added mocking of GetScopedEnvironment method in step execution context

* added mocking of GetScopedEnvironment method in step execution context

* changed default value for knob "AGENT_DRAIN_QUEUES_AFTER_TASK" to true

* implementd AsBooleanStrict and check in JobRunner

* Revert "implementd AsBooleanStrict and check in JobRunner"

This reverts commit a1c0c67.

* Reversed the knob

* Add issue templates (#4154)

* Add issue templates

* Update config.yml

* update templates

* Update config.yml

* Added knob to break pipeline unless user opt-in (#4165)

* Added knob to force agent fail if user doesn't opt-in updates on unsupported OS

* Resolved PR comments

---------

Co-authored-by: Kirill Ivlev <[email protected]>

* Merge remote-tracking branch 'origin/master' into upd_dotnet6_agent_mar2023

# Conflicts:
#	.azure-pipelines/build-job.yml
#	.azure-pipelines/pipeline.yml
#	.vsts.ci.yml
#	src/Agent.Sdk/Util/PlatformUtil.cs
#	src/Agent.Worker/JobRunner.cs
#	src/Agent.Worker/StepsRunner.cs
#	src/Agent.Worker/TaskRunner.cs
#	src/Common.props
#	src/Misc/layoutbin/installdependencies.sh
#	src/dev.sh

* Localization update (#4187)

* Added files for onelocbuild

* Update localize-pipeline.yml for Azure Pipelines

* Fixed typo in resource.resx path

* Removed en-US

* Update localize-pipeline.yml for Azure Pipelines

* LEGO: check in for Localization to temporary branch. (#3246)

* LEGO: check in for Localization to temporary branch. (#3268)

* LEGO: check in for Localization to temporary branch. (#3265)

* LEGO: check in for Localization to temporary branch. (#3279)

* Temporary renamed localization folders

* Renamed localization folders

* Set up schedule and notifications for the localization pipeline (#3269)

* [localization] Fixed localization pipeline issue with already localized strings replaced (#3332)

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 14646614

Localized file check-in by OneLocBuild Task

* LEGO: check in for Localization to temporary branch. (#3363)

Co-authored-by: csigs <[email protected]>

* LEGO: check in for Localization to temporary branch. (#3364)

Co-authored-by: csigs <[email protected]>

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 14919763

Localized file check-in by OneLocBuild Task

* Create PR in OneLocBuild task only on third week of sprint (#3374)

* Fix localization pipeline

* Add missed change

* Added option to disable PR creation

* update localize pipeline (#3637)

Co-authored-by: Ilya Kuleshov <[email protected]>

* Localization update (#3612)

* Removing Localize folder

* RHEL/CentOS 7 Fix for Lets Encrypt Change (#3601)

* Revert "RHEL/CentOS 7 Fix for Lets Encrypt Change (#3601)"

This reverts commit 629921e.

* Revert "Removing Localize folder"

This reverts commit 33cb0ae.

Co-authored-by: AndreyIvanov42 <[email protected]>
Co-authored-by: kuleshovilya <[email protected]>
Co-authored-by: Ilya Kuleshov <[email protected]>

* Removed OneLocBuild folder

* Move notifications about Agent Localization PR from Slack to MS Teams - Part 1 (#3744)

* Include strings from Misc/src/layoutbin to LocProject file (#4021)

* Update LocProject file

* Update CopyOption for LocProject

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 18665127 (#4022)

* Revert "Include strings from Misc/src/layoutbin to LocProject file (#4021)"

This reverts commit 8f5c0c0.

* Revert "Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 18665127 (#4022)" (#4023)

This reverts commit b9c714b.

* Include layoutbin into locproject

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 18680899 (#4028)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20221104175414554. (#4030)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20221105085259861. (#4031)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20221106085521421. (#4032)

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 18697046 (#4033)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20221107143113520. (#4039)

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 18706620 (#4044)

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 19415018 (#4163)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20230223095051399. (#4168)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20230224095040576. (#4170)

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 19476421 (#4179)

* Update loc strings

* Localized file check-in by OneLocBuild Task: Build definition ID 10944: Build ID 19476736 (#4181)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20230305095015478. (#4183)

* Juno: check in to lego/hb_5733438c-38c5-41ae-9557-a9d9754c4535_20230306095225210. (#4184)

* Removing Localize and OneLocBuild folder

---------

Co-authored-by: Anatolii Bolshakov (Akvelon INC) <[email protected]>
Co-authored-by: csigs <[email protected]>
Co-authored-by: Egor Bryzgalov <[email protected]>
Co-authored-by: Anatoly Bolshakov <[email protected]>
Co-authored-by: csigs <[email protected]>
Co-authored-by: Nikita Ezzhev <[email protected]>
Co-authored-by: kuleshovilya <[email protected]>
Co-authored-by: Ilya Kuleshov <[email protected]>
Co-authored-by: AndreyIvanov42 <[email protected]>
Co-authored-by: Denis Tikhomirov <[email protected]>
Co-authored-by: KonstantinTyukalov <[email protected]>

* Add "Mariner" to list of .NET 6 supporting systems (#4197)

* Cover unsupported OS failure with FF (#4196)

* Cover unsupported OS failure with FF

* Update strings.json

* Update JobRunner.cs

* Update JobRunner.cs

* Add knob to enable fetching net6.json file from GitHub (#4200)

* Added knob "AGENT_ENABLE_FETCHING_NET6_LIST"

* implemented knob EnableFetchingNet6List in function GetNet6SupportedSystems

* Removed RuntimeKnobSource for EnableFetchingNet6List

* removed logic which fails pipeline if there is some error occurred during checking if system supports .NET 6

* fixed typo

* Update autoAssignABTT.yml (#4201)

* Update AzureInstanceMetadataProvider.cs

---------

Co-authored-by: Roman-Shchukin <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Steve <[email protected]>
Co-authored-by: Denis Rumyantsev <[email protected]>
Co-authored-by: Rick Brown <[email protected]>
Co-authored-by: Liliia Sabitova <[email protected]>
Co-authored-by: Eric van Wijk <[email protected]>
Co-authored-by: Sergey Koryshev <[email protected]>
Co-authored-by: Konstantin Tyukalov <[email protected]>
Co-authored-by: Rami <[email protected]>
Co-authored-by: Martin <[email protected]>
Co-authored-by: ivanduplenskikh <[email protected]>
Co-authored-by: Roman Shchukin <[email protected]>
Co-authored-by: Your Name <[email protected]>
Co-authored-by: Merlyn Oppenheim <[email protected]>
Co-authored-by: İsmayıl İsmayılov <[email protected]>
Co-authored-by: Maksim Petrov <[email protected]>
Co-authored-by: Anatolii Bolshakov (Akvelon INC) <[email protected]>
Co-authored-by: csigs <[email protected]>
Co-authored-by: Egor Bryzgalov <[email protected]>
Co-authored-by: Anatoly Bolshakov <[email protected]>
Co-authored-by: csigs <[email protected]>
Co-authored-by: Nikita Ezzhev <[email protected]>
Co-authored-by: kuleshovilya <[email protected]>
Co-authored-by: Ilya Kuleshov <[email protected]>
Co-authored-by: AndreyIvanov42 <[email protected]>
Co-authored-by: Denis Tikhomirov <[email protected]>
Co-authored-by: Maxim Zaytsev <[email protected]>
  • Loading branch information
1 parent ba89226 commit b66c6e7
Show file tree
Hide file tree
Showing 27 changed files with 499 additions and 72 deletions.
69 changes: 69 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Bug
description: File a bug report
title: "[BUG]: "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: markdown
attributes:
value: |
## Having issue with Tasks?
Log an issue at [Azure-Pipelines-Tasks](https://github.com/Microsoft/azure-pipelines-tasks). It contains all of the in-box tasks we ship with Azure-Pipelines/VSTS/TFS. If you're having issues with tasks in Build/Release jobs (e.g. unreasonable task failure) please log an issue there.
- type: textarea
id: what-happened
attributes:
label: What happened?
description: What did you do? What happened? What did you expect to happen?
placeholder: Put your description of the bug here.
validations:
required: true
- type: textarea
id: versions
attributes:
label: Versions
description: Specify the agent version and operation system version
placeholder: Azure DevOps version 2.100.1 / Windows 10
validations:
required: true
- type: checkboxes
id: environment-type
attributes:
label: Environment type (Please select at least one enviroment where you face this issue)
options:
- label: Self-Hosted
- label: Microsoft Hosted
- label: VMSS Pool
- label: Container
- type: dropdown
id: azure-devops-type
attributes:
label: Azure DevOps Server type
options:
- dev.azure.com (formerly visualstudio.com)
- Azure DevOps Server (Please specify exact version in the textbox below)
validations:
required: true
- type: input
id: azure-devops-server-datails
attributes:
label: Azure DevOps Server Version (if applicable)
placeholder: Azure DevOps Server 2019.1
- type: input
id: operation-system
attributes:
label: Operation system
placeholder: Windows 11, Ubuntu 20.04...
- type: input
id: version-control-type
attributes:
label: Version controll system
- type: textarea
id: logs
attributes:
label: Relevant log output
description: |
Please copy and paste any relevant log output. You can find it in the _diag folder or on the pipelines logs on ADO side
render: shell
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
blank_issues_enabled: false
contact_links:
- name: Developer Community
url: https://developercommunity.visualstudio.com/AzureDevOps
about: For other Azure DevOps issues
- name: Tasks issue
url: https://github.com/microsoft/azure-pipelines-tasks/issues/new
about: If you have issues with tasks, please place your issues here.
- name: Security issue
url: https://github.com/microsoft/azure-pipelines-agent/security/policy
about: For security issues, please check our policy
- name: Issue with YAML
url: https://github.com/Microsoft/azure-pipelines-yaml
about: Over there we discuss YAML templates, samples for Azure Pipelines, and designs for upcoming YAML features. Also a place for the community to share best practices, ideas, and so on. File suggestions and issues here if they're specific to YAML pipelines.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Feature request
description: Use this template to submit a feature request
title: "[enhancement]: "
labels: ["enhancement"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to raise a question
- type: markdown
attributes:
value: |
## Having issue with Tasks?
Log an issue at [Azure-Pipelines-Tasks](https://github.com/Microsoft/azure-pipelines-tasks). It contains all of the in-box tasks we ship with Azure-Pipelines/VSTS/TFS. If you're having issues with tasks in Build/Release jobs (e.g. unreasonable task failure) please log an issue there.
- type: textarea
id: what-happened
attributes:
label: Describe your feature request here
placeholder: Put your question here.
description: Please try to provide as much details as possible
validations:
required: true
61 changes: 61 additions & 0 deletions .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Help needed
description: Raise a question
title: "[Question]: "
labels: ["helpwanted"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to raise a question
- type: markdown
attributes:
value: |
## Having issue with Tasks?
Log an issue at [Azure-Pipelines-Tasks](https://github.com/Microsoft/azure-pipelines-tasks). It contains all of the in-box tasks we ship with Azure-Pipelines/VSTS/TFS. If you're having issues with tasks in Build/Release jobs (e.g. unreasonable task failure) please log an issue there.
- type: textarea
id: what-happened
attributes:
label: Describe your question
placeholder: Put your question here.
validations:
required: true
- type: textarea
id: versions
attributes:
label: Versions
description: Specify the agent version and operation system version
placeholder: Azure DevOps version 2.100.1 / Windows 10
validations:
required: true
- type: checkboxes
id: environment-type
attributes:
label: Environment type (Please select at least one enviroment where you face this issue)
options:
- label: Self-Hosted
- label: Microsoft Hosted
- label: VMSS Pool
- label: Container
- type: dropdown
id: azure-devops-type
attributes:
label: Azure DevOps Server type
options:
- dev.azure.com (formerly visualstudio.com)
- Azure DevOps Server (Please specify exact version in the textbox below)
validations:
required: true
- type: input
id: operation-system
attributes:
label: Operation system
placeholder: Windows 11, Ubuntu 20.04...
- type: input
id: version-control-type
attributes:
label: Version controll system
- type: input
id: azure-devops-server-datails
attributes:
label: Azure DevOps Server Version (if applicable)
placeholder: Azure DevOps Server 2019.1
12 changes: 6 additions & 6 deletions .github/workflows/autoAssignABTT.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Auto Assign ABTT to Project Board

on:
issues:
types: [opened]
env:
MY_GITHUB_TOKEN: ${{ secrets.ABTT_TOKEN }}
types:
- opened

jobs:
assign_one_project:
Expand All @@ -18,8 +17,9 @@ jobs:
labels: |
Area: Agent
triage
- name: "Assign issues with 'Area: ABTT' label to project board"
uses: srggrs/assign-one-project[email protected]
uses: actions/add-to-project@v0.4.1
with:
project: 'https://github.com/orgs/microsoft/projects/48'
column_name: 'Backlog'
project-url: https://github.com/orgs/microsoft/projects/755
github-token: ${{ secrets.ABTT_TOKEN }}
8 changes: 8 additions & 0 deletions src/Agent.Listener/net6.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
}
]
},
{
"id": "mariner",
"versions": [
{
"name": "1.0+"
}
]
},
{
"id": "opensuse-leap",
"versions": [
Expand Down
1 change: 1 addition & 0 deletions src/Agent.Sdk/Agent.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" Condition="$(CodeAnalysis)=='true'" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="4.7.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="4.4.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.4.0" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="4.5.0" />
<PackageReference Include="vss-api-netcore" Version="$(VssApiVersion)" />
Expand Down
36 changes: 36 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,20 @@ public class AgentKnobs
"Disable agent downgrades. Upgrades will still be allowed.",
new EnvironmentKnobSource("AZP_AGENT_DOWNGRADE_DISABLED"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob AcknowledgeNoUpdates = new Knob(
nameof(AcknowledgeNoUpdates),
"Opt-in to continue using agent without updates on unsopperted OS",
new EnvironmentKnobSource("AGENT_ACKNOWLEDGE_NO_UPDATES"),
new RuntimeKnobSource("AGENT_ACKNOWLEDGE_NO_UPDATES"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob AgentFailOnIncompatibleOS = new Knob(
nameof(AgentFailOnIncompatibleOS),
"Allow agent to fail pipelines on incampatible OS",
new EnvironmentKnobSource("AGENT_FAIL_ON_INCOMPATIBLE_OS"),
new RuntimeKnobSource("AGENT_FAIL_ON_INCOMPATIBLE_OS"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob PermissionsCheckFailsafe = new Knob(
nameof(PermissionsCheckFailsafe),
Expand Down Expand Up @@ -402,11 +416,33 @@ public class AgentKnobs
new EnvironmentKnobSource(ContinueAfterCancelProcessTreeKillAttemptVariableName),
new BuiltInDefaultKnobSource("false"));

public const string VstsAgentNodeWarningsVariableName = "VSTSAGENT_ENABLE_NODE_WARNINGS";

public static readonly Knob AgentDeprecatedNodeWarnings = new Knob(
nameof(AgentDeprecatedNodeWarnings),
"If true shows warning on depricated node (6) tasks",
new RuntimeKnobSource(VstsAgentNodeWarningsVariableName),
new EnvironmentKnobSource(VstsAgentNodeWarningsVariableName),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob UseNode = new Knob(
nameof(UseNode),
"Forces the agent to use different version of Node if when configured runner is not available. Possible values: LTS - make agent use latest LTS version of Node; UPGRADE - make agent use next available version of Node",
new RuntimeKnobSource("AGENT_USE_NODE"),
new EnvironmentKnobSource("AGENT_USE_NODE"),
new BuiltInDefaultKnobSource(string.Empty));

public static readonly Knob DisableDrainQueuesAfterTask = new Knob(
nameof(DisableDrainQueuesAfterTask),
"Forces the agent to disable draining queues after each task",
new RuntimeKnobSource("AGENT_DISABLE_DRAIN_QUEUES_AFTER_TASK"),
new EnvironmentKnobSource("AGENT_DISABLE_DRAIN_QUEUES_AFTER_TASK"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob EnableFetchingNet6List = new Knob(
nameof(EnableFetchingNet6List),
"Forces the agent to fetch list of .NET 6 supporting systems from server",
new EnvironmentKnobSource("AGENT_ENABLE_FETCHING_NET6_LIST"),
new BuiltInDefaultKnobSource("false"));
}
}
82 changes: 82 additions & 0 deletions src/Agent.Sdk/Util/AzureInstanceMetadataProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net.Http;
using System.Text;
using System.Web;

namespace Agent.Sdk.Util
{
class AzureInstanceMetadataProvider : IDisposable
{
private HttpClient _client;
private const string _version = "2021-02-01";
private const string _azureMetadataEndpoint = "http://169.254.169.254/metadata";

public AzureInstanceMetadataProvider()
{
_client = new HttpClient();
}

public void Dispose()
{
_client?.Dispose();
_client = null;
}

private HttpRequestMessage BuildRequest(string url, Dictionary<string, string> parameters)
{
UriBuilder builder = new UriBuilder(url);

NameValueCollection queryParameters = HttpUtility.ParseQueryString(builder.Query);

if (!parameters.ContainsKey("api-version"))
{
parameters.Add("api-version", _version);
}

foreach (KeyValuePair<string, string> entry in parameters)
{
queryParameters[entry.Key] = entry.Value;
}

builder.Query = queryParameters.ToString();

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, builder.Uri);
request.Headers.Add("Metadata", "true");

return request;
}

public string GetMetadata(string category, Dictionary<string, string> parameters)
{
if (_client == null)
{
throw new ObjectDisposedException(nameof(AzureInstanceMetadataProvider));
}

using HttpRequestMessage request = BuildRequest($"{_azureMetadataEndpoint}/{category}", parameters);
HttpResponseMessage response = _client.SendAsync(request).Result;

if (!response.IsSuccessStatusCode)
{
string errorText = response.Content.ReadAsStringAsync().Result;
throw new Exception($"Error retrieving metadata category { category }. Received status {response.StatusCode}: {errorText}");
}

return response.Content.ReadAsStringAsync().Result;
}

public bool HasMetadata()
{
try
{
return GetMetadata("instance", new Dictionary<string, string> { ["format"] = "text" }) != null;
}
catch (Exception)
{
return false;
}
}
}
}
Loading

0 comments on commit b66c6e7

Please sign in to comment.