Could not find generated .deb file when trying to push it to Package Registry

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

  - test
  - build

  stage: test
    - echo "Running unit tests..."
    - go test -cover ./...

  stage: test
    - echo "Linting go code..."
    - go vet ./...

  stage: build
    - echo "Building debian archives..."
    - bash maint-scripts/

Things to note in above config:

  1. 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.
  2. My build stage actually calls a script, I’ve listed a minimal version of it below.
version=0.1.0  # this should be dynamically set

for arch in amd64 arm64

    dpkg-deb --build --root-owner-group $archDir $outputDir

    echo `pwd`
    ls $outputDir

    rm -r $archDir

    [ -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

What I expect from above command is to print these things to CI console:

  1. echo `pwd`: This should print the project root.
  2. ls $outputDir: This should print the contents of dist/ directory in pwd. This directory should have the deb files which is generated by the dpkg-deb command.
  3. 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'.
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.

  1. I see the output of dpkg-deb command.
  2. I see outupt of the echo pwd command.
  3. ls $outputDir should be printing the my-app_0.1.0_amd64.deb file which it didn’t.
  4. deb archive exists, pushing to Package Registry also didn’t get printed, which means file indeed didn’t exist.

I’m using version of gitlab. Running with gitlab-runner 15.1.0 (76984217) on Docker GitLab Runner jySoWYRJ

I did some investigation at the runner end. Found out that dist/ was not considered as a directory but the binary file. This is specific to dpkg-deb.

The binary was created at dist file. If a directory is created at dist/, the binary is then created inside it with the specific names.

My solution was to create a dist/ directory before entering for loop.

1 Like