-
Notifications
You must be signed in to change notification settings - Fork 380
Update pipeline to create/destroy azure resource dynamically #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ewertons
wants to merge
29
commits into
main
Choose a base branch
from
ewertons/pipelinefixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
551deae
Test vmImage ubuntu-20.04 for some jobs of python-nightly
ewertons 1ca0d35
Use ubuntu-22.04 instead
ewertons fe17871
Install mixing package 'six' in test requirements
ewertons 497277e
Attempt to create azure resources in pipeline
ewertons 8e8f30d
Fix stage names
ewertons 1459d75
Fix jobs names
ewertons 46b76f1
Explicitly use a linux host
ewertons 347cc6c
Try using task AzureCLI@2 in pipeline
ewertons ab8c6f3
Try using task AzureCLI@2 in pipeline
ewertons dd9f9f4
Define and use dynamic variables
ewertons 3387c89
Define and use dynamic variables
ewertons 1e29b6d
Define and use dynamic variables
ewertons f7a6127
Define and use dynamic variables
ewertons 51b2299
Define and use dynamic variables
ewertons f8a8f67
Define and use dynamic variables
ewertons 980bea8
Define and use dynamic variables
ewertons 80a9cfc
Define and use dynamic variables
ewertons 9232736
Define and use dynamic variables
ewertons 3100282
Re-enable other variants of python version tests
ewertons 9272daa
Disable failing tests
ewertons 2551e16
Try fix last step in yaml to propagate variable correctly
ewertons dc87bc1
Propage vars to last stage
ewertons 772f694
Propage vars to last stage
ewertons 3a47657
Propage vars to last stage
ewertons 91d079c
Clean up yaml
ewertons 45a4d45
Add comment about six package in requirements_test.txt
ewertons 44e2592
Update pool to ubuntu 22.04 on build.yaml
ewertons ed50c9d
Fix vmImage label name to ubuntu-24.04
ewertons b44f543
Disable static analysis job in build.yaml due to failures
ewertons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,84 +1,145 @@ | ||
| name: $(BuildID)_$(BuildDefinitionName)_$(SourceBranchName) | ||
|
|
||
| jobs: | ||
| - job: 'Test' | ||
|
|
||
| strategy: | ||
| maxParallel: 4 | ||
| matrix: | ||
| py39_windows_mqtt: | ||
| pv: '3.9' | ||
| transport: 'mqtt' | ||
| imageName: 'windows-latest' | ||
| consumerGroup: 'cg1' | ||
| py39_windows_mqttws: | ||
| pv: '3.9' | ||
| transport: 'mqttws' | ||
| imageName: 'windows-latest' | ||
| consumerGroup: 'cg2' | ||
| py38_linux_mqttws: | ||
| pv: '3.8' | ||
| transport: 'mqttws' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg4' | ||
| py38_linux_mqtt: | ||
| pv: '3.8' | ||
| transport: 'mqtt' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg5' | ||
| py39_linux_mqttws: | ||
| pv: '3.9' | ||
| transport: 'mqttws' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg6' | ||
| py310_linux_mqtt: | ||
| pv: '3.10' | ||
| transport: 'mqtt' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg7' | ||
| py311_linux_mqtt: | ||
| pv: '3.11' | ||
| transport: 'mqtt' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg8' | ||
| py312_linux_mqtt: | ||
| pv: '3.12' | ||
| transport: 'mqtt' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg9' | ||
| py312_linux_mqttws: | ||
| pv: '3.12' | ||
| transport: 'mqttws' | ||
| imageName: 'Ubuntu 20.04' | ||
| consumerGroup: 'cg10' | ||
|
|
||
|
|
||
| pool: | ||
| vmImage: $(imageName) | ||
|
|
||
| steps: | ||
| - task: UsePythonVersion@0 | ||
| stages: | ||
| - stage: setup | ||
| jobs: | ||
| - job: create_iot_hub_and_dps | ||
| pool: | ||
| vmImage: 'ubuntu-24.04' | ||
| steps: | ||
| - script: | | ||
| sudo apt-get install -y uuid | ||
| AZURE_RESOURCE_GROUP="aziotsdkpython$(uuid)" | ||
| AZURE_IOTHUB_NAME="aziotsdkpython$(uuid)" | ||
|
|
||
| # Export variables to other stages/jobs/steps. | ||
| echo "##vso[task.setvariable variable=AZURE_RESOURCE_GROUP;isOutput=true]$AZURE_RESOURCE_GROUP" | ||
| echo "##vso[task.setvariable variable=AZURE_IOTHUB_NAME;isOutput=true]$AZURE_IOTHUB_NAME" | ||
| name: setResourceNames | ||
| displayName: Set Azure Resource Names | ||
| - task: AzureCLI@2 | ||
| inputs: | ||
| versionSpec: $(pv) | ||
| architecture: 'x64' | ||
| azureSubscription: 'iot hub sdk service connection' | ||
| scriptType: 'bash' | ||
| scriptLocation: 'inlineScript' | ||
| inlineScript: | | ||
| set -e | ||
|
|
||
| - script: 'python scripts/env_setup.py --no_dev' | ||
| displayName: 'Prepare environment (install packages + dev dependencies + test dependencies + tools)' | ||
| export AZURE_RESOURCE_GROUP=$(setResourceNames.AZURE_RESOURCE_GROUP) | ||
| export AZURE_IOTHUB_NAME=$(setResourceNames.AZURE_IOTHUB_NAME) | ||
|
|
||
| - script: | | ||
| cd $(Build.SourcesDirectory)/tests/e2e/iothub_e2e | ||
| echo "Using consumer group: ${IOTHUB_E2E_EVENTHUB_CONSUMER_GROUP}" | ||
| # "not x" means "include all tests that don't have the tag named 'x'", which is everything. | ||
| pytest --transport=$(transport) --junitxml=junit/TEST-python-e2e.xml -o junit_suite_name="$(Agent.JobName)" -m "not x" | ||
| displayName: 'E2E Device Client MQTT Connection String' | ||
| env: | ||
| IOTHUB_E2E_IOTHUB_CONNECTION_STRING: $(IOTHUB-E2E-CONNECTION-STRING) | ||
| IOTHUB_E2E_EVENTHUB_CONNECTION_STRING: $(IOTHUB-E2E-EVENTHUB-CONNECTION-STRING) | ||
| IOTHUB_E2E_EVENTHUB_CONSUMER_GROUP: $(consumerGroup) | ||
| PYTHONUNBUFFERED: True | ||
|
|
||
| - task: PublishTestResults@2 | ||
| displayName: 'Publish Test Results' | ||
|
|
||
| condition: always() | ||
| az group create -g $AZURE_RESOURCE_GROUP -l $(AZURE_REGION) | ||
|
|
||
| time az iot hub create -g $AZURE_RESOURCE_GROUP -n $AZURE_IOTHUB_NAME --dla false --mintls 1.2 --partition-count 4 --sku S1 | ||
|
|
||
| export IOTHUB_CONNECTION_STRING=$(az iot hub connection-string show -g $AZURE_RESOURCE_GROUP --hub-name $AZURE_IOTHUB_NAME --pn iothubowner --query "connectionString" --output tsv) | ||
| export EVENTHUB_CONNECTION_STRING=$(az iot hub connection-string show -g $AZURE_RESOURCE_GROUP --hub-name $AZURE_IOTHUB_NAME --eh --query "connectionString" --output tsv) | ||
|
|
||
| for i in $(seq 1 7); do | ||
| cg_name="cg$i" | ||
| az iot hub consumer-group create -g "$AZURE_RESOURCE_GROUP" --hub-name "$AZURE_IOTHUB_NAME" --name "$cg_name" | ||
| done | ||
|
|
||
| # Export variables to other stages/jobs/steps. | ||
| echo "##vso[task.setvariable variable=IOTHUB_CONNECTION_STRING;isOutput=true]$IOTHUB_CONNECTION_STRING" | ||
| echo "##vso[task.setvariable variable=EVENTHUB_CONNECTION_STRING;isOutput=true]$EVENTHUB_CONNECTION_STRING" | ||
| displayName: Create IoT Hub & DPS | ||
| name: createAzureResources | ||
| - stage: build_and_tests | ||
| jobs: | ||
| - job: 'Test' | ||
| variables: | ||
| IOTHUB_CONNECTION_STRING: $[stageDependencies.setup.create_iot_hub_and_dps.outputs['createAzureResources.IOTHUB_CONNECTION_STRING']] | ||
| EVENTHUB_CONNECTION_STRING: $[stageDependencies.setup.create_iot_hub_and_dps.outputs['createAzureResources.EVENTHUB_CONNECTION_STRING']] | ||
| strategy: | ||
| maxParallel: 4 | ||
| matrix: | ||
| py39_windows_mqtt: | ||
| pv: '3.9' | ||
| transport: 'mqtt' | ||
| imageName: 'windows-latest' | ||
| consumerGroup: 'cg1' | ||
| py39_windows_mqttws: | ||
| pv: '3.9' | ||
| transport: 'mqttws' | ||
| imageName: 'windows-latest' | ||
| consumerGroup: 'cg2' | ||
| py39_linux_mqttws: | ||
| pv: '3.9' | ||
| transport: 'mqttws' | ||
| imageName: 'ubuntu-22.04' | ||
| consumerGroup: 'cg3' | ||
| py310_linux_mqtt: | ||
| pv: '3.10' | ||
| transport: 'mqtt' | ||
| imageName: 'ubuntu-22.04' | ||
| consumerGroup: 'cg4' | ||
| py311_linux_mqtt: | ||
| pv: '3.11' | ||
| transport: 'mqtt' | ||
| imageName: 'ubuntu-22.04' | ||
| consumerGroup: 'cg5' | ||
| py312_linux_mqtt: | ||
| pv: '3.12' | ||
| transport: 'mqtt' | ||
| imageName: 'ubuntu-22.04' | ||
| consumerGroup: 'cg6' | ||
| py312_linux_mqttws: | ||
| pv: '3.12' | ||
| transport: 'mqttws' | ||
| imageName: 'ubuntu-22.04' | ||
| consumerGroup: 'cg7' | ||
|
|
||
|
|
||
| pool: | ||
| vmImage: $(imageName) | ||
|
|
||
| steps: | ||
| - task: UsePythonVersion@0 | ||
| inputs: | ||
| versionSpec: $(pv) | ||
| architecture: 'x64' | ||
| addToPath: true | ||
| - script: 'python scripts/env_setup.py --no_dev' | ||
| displayName: 'Prepare environment (install packages + dev dependencies + test dependencies + tools)' | ||
|
|
||
| - script: | | ||
| cd $(Build.SourcesDirectory)/tests/e2e/iothub_e2e | ||
| echo "Using consumer group: ${IOTHUB_E2E_EVENTHUB_CONSUMER_GROUP}" | ||
| # "not x" means "include all tests that don't have the tag named 'x'", which is everything. | ||
| pytest --transport=$(transport) --junitxml=junit/TEST-python-e2e.xml -o junit_suite_name="$(Agent.JobName)" -m "not x" | ||
| displayName: 'E2E Device Client MQTT Connection String' | ||
| env: | ||
| IOTHUB_E2E_IOTHUB_CONNECTION_STRING: $(IOTHUB_CONNECTION_STRING) | ||
| IOTHUB_E2E_EVENTHUB_CONNECTION_STRING: $(EVENTHUB_CONNECTION_STRING) | ||
| IOTHUB_E2E_EVENTHUB_CONSUMER_GROUP: $(consumerGroup) | ||
| PYTHONUNBUFFERED: True | ||
|
|
||
| - task: PublishTestResults@2 | ||
| displayName: 'Publish Test Results' | ||
|
|
||
| condition: always() | ||
| - stage: cleanup | ||
| dependsOn: | ||
| - setup | ||
| - build_and_tests | ||
| condition: always() # Run stage even if the pipeline run is cancelled. | ||
| jobs: | ||
| - job: destroy_azure_resource_group | ||
| condition: always() # Run job even if the pipeline run is cancelled. | ||
| variables: | ||
| AZURE_RESOURCE_GROUP: $[stageDependencies.setup.create_iot_hub_and_dps.outputs['setResourceNames.AZURE_RESOURCE_GROUP']] | ||
| steps: | ||
| - task: AzureCLI@2 | ||
| inputs: | ||
| azureSubscription: 'iot hub sdk service connection' | ||
| scriptType: 'bash' | ||
| scriptLocation: 'inlineScript' | ||
| inlineScript: | | ||
| # set -e | ||
|
|
||
| printenv | sort | grep -i azure | ||
|
|
||
| time az group delete --name $(AZURE_RESOURCE_GROUP) --yes | ||
| displayName: Destroy Azure Resource Group | ||
| condition: always() # Run step even if the pipeline run is cancelled. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to update these to include Python 3.13 and Python 3.14 - the modern versions people actually use.
I think we can safely delete the commented lines about 3.8 since Azure ended support for 3.8 in April of this year. 3.9 support is dropping in April 2026.
Adding 3.13 and 3.14 could be a follow up, but I'd go ahead and remove the 3.8 lines now.