Gitlab Runners as Containers

Hello everyone,
i am trying out the CI/CD pipeline of Gitlab (i don’t have experience of DevOps but it’s something that is needed in the company i am employed of). I have created a runner as “docker” (using a docker image of Gradle) and i have pushed a small java application to a new repository in Gitlab. My pipeline has only one job named “build”. The task of it is “gradle build”. The pipeline is successful but i don’t really know of how to extract the created .jar file from the build process. By extract i mean, how to copy the .jar file to the “outside world”. :slight_smile:

Can anyone please explain to me the process? Actually i am not looking for a walk-through. I want to understand how this works because in the future we are going to be creating more pipelines.

Best regards and thank you so much in advance.

Hi there, so you want something like this:

stages:
   - build

build:
    ...
    script:
       - gradle build
    artifacts:
        paths
            - myjarfile.jar
         expire_in: 2 weeks 

And then once your pipeline has run, on your pipeline page you should see a label Actions near you pipeline, and a drop-down that will give you the option to download the file (or a zip archive containing the file).

1 Like

Hi @snim2,
thank you so much for your quick response! I have tried this but the reason as to “why” i want to copy the created .jar file outside of the build container is in order to package it to another container and publish it to a private docker registry. I am thinking that maybe i am way over my head with this one but i want to start learning about CI/CD.

Best regards.

Oh, in that case, you probably want to add another stage called package to do the next step, and then a publish stage. Artifacts should automatically be passed from one stage to another.

Do read through the GitLab docs they are quite readable and comprehensive, IMO!

Hi @snim2, thank you so much for the documentation link. One thing i cannot quite understand yet, is the fact that when i created the gitlab runner i “attached” the gradle docker image to it. How in my pipeline can add more images? I mean, maybe i should have attached a more “generic” linux image to it. How proper DevOps people are doing this?

Best regards.

When you created your runner, you added a default image to it. You can have use any number of images in your actual pipeline:

build:
    ...
    image: gradle:VERSION
    script:
       - gradle build
    artifacts:
        paths
            - myjarfile.jar
         expire_in: 2 weeks 
1 Like

Oh! This means that no matter what kind of docker image i attach to the runner during the initial registration can be “overwritten” during the pipeline’s lifetime?

Best regards.

Yep, absolutely.