I have a 2 stage GitLab Pipeline. In first stage I test and in second stage I build and publish to GitLab Package Registry.
Here is my .gitlab-ci.yml:
image: sntshk/ubuntu:nunet
stages:
- test
- build
unit-test-job:
stage: test
script:
- echo "Running unit tests..."
- go test -cover ./...
lint-test-job:
stage: test
script:
- echo "Linting go code..."
- go vet ./...
build-job:
stage: build
script:
- echo "Building debian archives..."
- bash maint-scripts/build.sh
Things to note in above config:
- I’m using a custom image. This is because my build script has dependencies like golang, gcc, dpkg-deb. That docker image has all of them.
- My build stage actually calls a script, I’ve listed a minimal version of it below.
projectRoot=$(pwd)
outputDir="$projectRoot/dist"
version=0.1.0 # this should be dynamically set
for arch in amd64 arm64
do
archDir=$projectRoot/maint-scripts/my-app_$version\_$arch
dpkg-deb --build --root-owner-group $archDir $outputDir
echo `pwd`
ls $outputDir
rm -r $archDir
debArchive=${projectRoot}/dist/my-app_${version}_${arch}.deb
[ -f $debArchive ] && echo "deb archive exists, pushing to Package Registry"
curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ${projectRoot}/dist/my-app_${version}_${arch}.deb ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/my-app/${version}/my-app_${version}_${arch}.deb
done
What I expect from above command is to print these things to CI console:
- echo `pwd`: This should print the project root.
-
ls $outputDir
: This should print the contents ofdist/
directory in pwd. This directory should have the deb files which is generated by thedpkg-deb
command. - deb archive exists, pushing to Package Registry: There is a conditional which I created in process of investigation.
Here is what I see instead:
dpkg-deb: building package 'my-app' in '/tmp/builds/jySoWYRJ/0/my-org/my-repo/dist'.
/tmp/builds/jySoWYRJ/0/my-org/my-repo
ls /tmp/builds/jySoWYRJ/0/my-org/my-repo/dist
curl: Can't open '/tmp/builds/jySoWYRJ/0/my-org/my-repo/dist/my-app_0.1.0_amd64.deb'!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (26) Failed to open/read local data from file/application
For simplicity sake, I’ve only included amd64 iterate of the for loop. Here is explanation of what’s in the output and what I was expecting.
- I see the output of dpkg-deb command.
- I see outupt of the
echo pwd
command. -
ls $outputDir
should be printing themy-app_0.1.0_amd64.deb
file which it didn’t. -
deb archive exists, pushing to Package Registry
also didn’t get printed, which means file indeed didn’t exist.
I’m using gitlab.com version of gitlab. Running with gitlab-runner 15.1.0 (76984217) on Docker GitLab Runner jySoWYRJ