skip to Main Content

I have a sample project with a simple C file( hello world program). I am trying to get familiar with artifacts and hence I have started with pipeline artifacts. The pipeline has 2 stages, build and Test.
In the build stage, I compile the C file, then publish the artifact. In the test stage, I run the object file.

trigger:
  branches:
    include:
      - '*'
pool:
  vmImage: ubuntu-latest

stages:
  - stage: build
    jobs:
      - job: buildjob
        steps:
          - script: |
              echo "building the test.c file"
              gcc test.c -o test
              echo "build completed"
        
          - task: PublishPipelineArtifact@1
            inputs:
              targetPath: $(System.DefaultWorkingDirectory)
              artifactName: Test
  - stage: test
    jobs:    
      - job: testJob
        steps:
          - download: current
            artifact: Test
          - script: |
              cd Test
              echo "Running the object file"
              ./test
              echo "job finished"

Error:
Error

I can see that the artifacts have been published:
Artifacts

Concerns: What do I have to do to get the object file running`? Also can i just pass the object file alone to the artifact? How?

UPDATE
I have managed to find the correct path to the artifact folder. But I cannot seem to execute the file. It shows permission denied

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
  branches:
    include:
      - '*'
pool:
  vmImage: ubuntu-latest

stages:
  - stage: build
    jobs:
      - job: buildjob
        steps:
          - script: |
              echo "building the test.c file"
              gcc test.c -o test
              echo "build completed"
        
          - task: PublishPipelineArtifact@1
            inputs:
              targetPath: $(System.DefaultWorkingDirectory)
              artifactName: Test
  - stage: test
    jobs:    
      - job: testJob
        steps:
          - download: current
            artifact: Test
          - script: |
              echo "Running the object file"
              cd  $(Pipeline.Workspace)/Test
              ./test
              echo "job finished"

New Error: Permission denied error

2

Answers


  1. The execute permission bit on your compiled executable was lost between stages. When the file is downloaded in stage "test", it does not have the execute bit set anymore hence the "Permission denied" error when you try to runit.

    Setting the x bit again by adding via chmod will solve this:

      - stage: test
        jobs:    
          - job: testJob
            steps:
              - download: current
                artifact: Test
              - script: |
                  echo "Running the object file"
                  cd  $(Pipeline.Workspace)/Test
                  chmod +x ./test
                  ./test
                  echo "job finished"
    
    Login or Signup to reply.
  2. The issue is that under Linux the file permission get lost through the compression via zip.

    A working solution would be to use tar as it preserves the file permissions.

    PublishBuildArtifacts

    StoreAsTar – Tar the artifact before uploading
    boolean. Default value: false.

    Adds all files from the publish path to a tar archive before uploading. This allows you to preserve the UNIX file permissions. Use extractTars option of theDownloadBuildArtifacts task to extract the downloaded items automatically. This setting is ignored on Windows agents.

    DownloadBuildArtifacts

    extractTars – Extract all files that are stored inside tar archives
    boolean.

    Set to true to extract all downloaded files that have the .tar extension. This is helpful because you need to pack your artifact files into tar if you want to preserve Unix file permissions. Enabling the StoreAsTar option in the Publish build artifacts task will store artifacts as .tar files automatically.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search