Hanamant
Hanamant

Reputation: 44

is there any way to pass variables from CI to CD pipeline

I have some logic to find calculate variable in CI pipeline and want this variable to access in CD pipeline. is there any way. Is setting variable like below, would that be accessible in CD ?

  echo "##vso[task.setvariable variable=CALC;isOutput=true]${VALUE}"

I don't want to use the variable group here to set and access. Any other way than variable group ?

Upvotes: 0

Views: 1104

Answers (1)

Kim Xu-MSFT
Kim Xu-MSFT

Reputation: 2206

In your CI pipeline, you could put your variable into a .txt file and publish the .txt file to Artifacts

trigger:
- none
pool:
  vmImage: ubuntu-latest
parameters:
  - name: projectName
    displayName: project name?
    type: string
steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $variable = '${{parameters.projectName}}'
      $variable | Out-file $(Build.ArtifactStagingDirectory)\projectname.txt
      Get-Content $(Build.ArtifactStagingDirectory)\projectname.txt
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: Container

I set 0615 as variable to pass

enter image description here

In your CD pipeline, Download Build Artifacts and get the variable from the .txt file

enter image description here

enter image description here

$myValue = Get-Content $(System.ArtifactsDirectory)/drop/projectname.txt;
Write-Host $myValue

#Write-Host "##vso[task.setvariable variable=ProjectName]($myVaule)";

enter image description here

Upvotes: 2

Related Questions