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"
I can see that the artifacts have been published:
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"
2
Answers
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:
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
DownloadBuildArtifacts