Skip to content
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

Install sonic yangs during pipeline build #124

Merged
merged 2 commits into from
Feb 12, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ trigger:
branches:
include:
- master
- 202???

pr:
branches:
include:
- master
- 202???

variables:
- name: BUILD_BRANCH
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
value: $(System.PullRequest.TargetBranch)
${{ else }}:
value: $(Build.SourceBranchName)

resources:
repositories:
- repository: sonic-mgmt-common
type: github
name: sonic-net/sonic-mgmt-common
endpoint: sonic-net
ref: refs/heads/$(BUILD_BRANCH)

stages:
- stage: Build
Expand All @@ -42,18 +52,19 @@ stages:
- checkout: sonic-mgmt-common
clean: true
submodules: recursive
displayName: 'Checkout code'
displayName: 'Checkout sonic-mgmt-common'

- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: build
pipeline: 1
pipeline: 142
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can dynamically retrieve the pipeline ID using the Azure DevOps CLI or REST API. Then, set the pipeline ID as a variable to avoid hardcoding it in your configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a declarative yaml file, cannot run commands.. I just followed the existing logic where pipeline id 1 was hardcoded.. There is no dynamic pipeline requirement here -- idea is to download yang & libyang from the latest official vs build, which is pipeline 142. Anyway tried changing it to the pipeline name and it worked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Azure pipeline YAML configuration allows you to dynamically retrieve and use the pipeline ID to avoid hardcoding it.
e.g.

- script: |
    PIPELINE_ID=$(curl -k "https://dev.azure.com/mssonic/build/_apis/pipelines?api-version=7.1" | jq -r '.value[] | select(.name=="Azure.sonic-buildimage.official.generic") | .id')
  displayName: 'Get Pipeline ID'

- task: DownloadPipelineArtifact@2
  inputs:
    source: specific
    project: build
    pipeline: $(PIPELINE_ID)
. . .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the script local variable automatically get exported as pipeline variable?

Anyway, did you check the latest? I have used the pipeline name instead of id.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I notice the pipeline id has been replaced with the pipeline name. No hardcoding, which resolves my comment.

artifact: sonic-buildimage.vs
runVersion: 'latestFromBranch'
runBranch: 'refs/heads/master'
runBranch: 'refs/heads/$(BUILD_BRANCH)'
patterns: |
target/debs/bookworm/libyang*.deb
target/python-wheels/bookworm/sonic_yang_models*.whl
displayName: "Download sonic buildimage"

- script: |
Expand All @@ -80,18 +91,21 @@ stages:
[[ ! -f python3_requirements.txt ]] || \
sudo pip3 install --no-cache-dir -r python3_requirements.txt

popd
displayName: "Install dependency"

- script: |
sudo pip3 install ../target/python-wheels/bookworm/sonic_yang_models-1.0-py3-none-any.whl
displayName: "Install sonic yangs"

- script: |
set -ex
pushd sonic-mgmt-common

NO_TEST_BINS=1 dpkg-buildpackage -rfakeroot -b -us -uc -j$(nproc)

displayName: "Install dependency"
displayName: "Build sonic-mgmt-common"

- script: |
set -ex
ls -l

pushd sonic-mgmt-framework

dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) && cp ../*.deb $(Build.ArtifactStagingDirectory)/
Expand Down
Loading