RCB
RCB

Reputation: 491

Using published pipeline artifact in azure devops using YAML

I have a simple helloworld c++ program, and I am writing a pipeline to get familiar with the azure environment. However, I have created multiple stages, with individual jobs inside the stages. I have a build stage where I compile my source code to produce an object file.

I can execute the file in the same job without any issues, however I want to create a separate stage for execution. Since I need to share the files now between stages, I use pipeline artifact. However, I am not able to download the artifact. It produces an error - "Unexpected value ''" at line 37.

trigger:
- main

pool:
  vmImage: ubuntu-latest


stages:
  - stage: Analysis
    jobs:
      - job: AnalyisJob
        steps:
          - script: echo Analysing the cpp file
  
  - stage: Build
    jobs:
      - job: BuildJob
        steps:
          - script: |
              echo compiling the cpp file
              g++ helloworld.cpp -o helloworld
              echo finished compiling
              echo "publishing the object file"
          - publish: 
            target: '$(Pipeline.Workspace)'
            artifact: 'MyArtifact'

  - stage: Test
    jobs:
      - job: Test
        steps:
          - download:                  #ERROR LINE 37
            artifact: 'MyArtifact'
          - script: |
              echo running the cpp file
              ./helloworld

Any suggestions to overcome this?


UPDATE

I used the suggestion and got the error rectified, but now I face permission denied error to run by object file.

trigger:
- main

pool:
  vmImage: ubuntu-latest


stages:
  - stage: Analysis
    jobs:
      - job: AnalyisJob
        steps:
          - script: echo Analysing the cpp file
  
  - stage: Build
    jobs:
      - job: BuildJob
        steps:
          - script: |
              echo compiling the cpp file
              g++ helloworld.cpp -o helloworld
              echo finished compiling
              echo "publishing the contents"
          - publish: $(System.DefaultWorkingDirectory)
            artifact: MyArtifact

  - stage: Test
    jobs:
      - job: Test
        steps:
         - download: current
           artifact: MyArtifact
         - script: |
              echo running the cpp file
              cd  $(Pipeline.Workspace)/MyArtifact
              ./helloworld

The error image : Error

Upvotes: 1

Views: 712

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41755

You need to add current:

- download: current

See the docs here.

Upvotes: 1

Related Questions