Permission issue while executing downloaded pipeline artifact in Azure devops CI

Viewed 18

I am using multiple stages in my pipeline to understand the different paradigms. To share files between stages, I made use of pipeline artifacts. Building in one stage and testing the result in another. To support this, I have a simple C file, which prints hello.

My pipeline

trigger:
- main

pool:
  vmImage: ubuntu-latest

stages:
- stage: Build
    jobs:
      - job: BuildJob
        steps:
          - script: |
              echo compiling the c file
              gcc hello.c -o hello
              echo finished compiling
              echo "publishing the contents"
          - publish: $(System.DefaultWorkingDirectory)
            artifact: myobj

  - stage: Test
    jobs:
      - job: Testing
        steps:
         - download: current
           artifact: myobj
         - script: |
              cd  $(Pipeline.Workspace)/myobj
              ./hello

I get following error message :

/home/vsts/work/_temp/3ba036fd-22vm0-4e54-b5a4-3ce3ce00f7e6.sh: line 4: ./hello: Permission denied
##[error]Bash exited with code '126'.

Is there anything conceptual that I am missing? Or in the script?

1 Answers

Restoring the artifact hasn't restored the executable bit on the build outcome.

Add a script step that does:

chmod +x ./hello

Or add it to your existing script:

         - script: |
              cd  $(Pipeline.Workspace)/myobj
              chmod +x ./hello
              ./hello
Related