#I am trying to setup runner, but I can't quite figure it out.
34 messages ยท Page 1 of 1 (latest)
I now use this file
copy_to_local_server:
stage: deploy
script:
- |
# Define variables
REPO_URL="https://gitlab.com/Tim098b/timwens.ink.git"
LOCAL_DIR="/var/www/html/timwensink/"
BRANCH="main" # Change this to your default branch name if it's not "main"
# Navigate to the local server directory
cd $LOCAL_DIR
# Clone the repository
git clone $REPO_URL temp_repo
# Navigate into the cloned repository
cd temp_repo
# Checkout the default branch
git checkout $BRANCH
# Copy the files to the local server directory
cp -r * $LOCAL_DIR
# Clean up - remove the temporary clone
cd ..
rm -rf temp_repo
only:
- main # Adjust this to your desired branch if different
But it gives this error:
Running with gitlab-runner 16.6.0~beta.105.gd2263193 (d2263193)
on blue-5.saas-linux-small-amd64.runners-manager.gitlab.com/default -AzERasQ, system ID: s_4cb09cee29e2
feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor
00:19
Using Docker executor with image ruby:3.1 ...
Pulling docker image ruby:3.1 ...
Using docker image sha256:5cd1ffe2802975362ac267390dbf21810460e86b2e7ce5cb4b4870db9f579e6c for ruby:3.1 with digest ruby@sha256:08ae8c16a2de19fe4ec47613e7757c5d572cf28859685ccc29e0e52b7225c400 ...
Preparing environment
00:05
Running on runner--azerasq-project-54857924-concurrent-0 via runner-azerasq-s-l-s-amd64-1707768360-9486058a...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/Tim098b/timwens.ink/.git/
Created fresh repository.
Checking out be38d5f2 as detached HEAD (ref is main)...
Skipping Git submodules setup
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:00
Using docker image sha256:5cd1ffe2802975362ac267390dbf21810460e86b2e7ce5cb4b4870db9f579e6c for ruby:3.1 with digest ruby@sha256:08ae8c16a2de19fe4ec47613e7757c5d572cf28859685ccc29e0e52b7225c400 ...
$ # Define variables # collapsed multi-line command
/usr/bin/bash: line 145: cd: /var/www/html/timwensink/: No such file or directory
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
This also doesn't seem to work
copy_to_local_server:
stage: deploy
script:
- |
# Define environment variables (replace with your values)
REPO_URL=${CI_REPOSITORY_URL} # GitLab repository URL (masked in logs)
LOCAL_DIR=/var/www/html/timwens.ink # Local directory for website files
BRANCH=main # Branch to deploy (adjust if needed)
# Install required dependencies (if applicable)
- apt-get update && apt-get install -y git
# Ensure local directory exists and has correct permissions
- mkdir -p "$LOCAL_DIR" && chown -R www-data:www-data "$LOCAL_DIR"
# Clone the repository
- git clone --branch="$BRANCH" --single-branch --depth=1 "$REPO_URL" "$LOCAL_DIR"
# Alternatively, if authentication is required:
- |
git clone --branch="$BRANCH" --single-branch --depth=1 "$REPO_URL" "$LOCAL_DIR"
cd "$LOCAL_DIR"
git remote set-url origin "$CI_REPOSITORY_URL"
git config user.email "[BOT] GitLab Runner <gitlab-ci-runner@your-gitlab-domain.com>"
git config user.name "GitLab Runner"
git fetch --unshallow --tags origin "$BRANCH"
git checkout "$BRANCH"
# Clear cache and restart web server (adjust commands based on your server)
- service apache2 reload # Replace with appropriate command for your web server
only:
- main # Or adjust to your desired trigger branch(es)
The issue isn't your script, it's that you're using shared runners, which means the CI job is running on a remote server. Do you also have GitLab runner installed on your pi? If not, you'll likely need to install a shell runner for a workflow like this to work
Ok, make sure you have that runner tagged, and you add that tag to your job so it's bound to just that runner
I have GitLab Runner installed on my Raspberry Pi
So the tag is copy_to_local_server?
Sorry @hidden panther , I missed responding to this yesterday ๐
The tag is something you apply to your job separately from the job name, so your job would look like this:
copy_to_local_server:
stage: deploy
tags:
- my_runner_tag
script:
The value for the tag would come from when you setup your runner. It would have asked for whether you had specific tags you wanted the runner to pick up. The value you provided there would go under "Tags". If you didn't provide a value, I'd recommend re-registering the runner with a specific tag provided, so you can use the tag in your job ๐
No problem
This script seems to finish the job
copy_to_local_server:
stage: deploy
script:
- |
REPO_URL=${CI_REPOSITORY_URL}
LOCAL_DIR=/var/www/html/timwensink/
BRANCH=main
git clone --branch="$BRANCH" --single-branch --depth=1 "$REPO_URL" "$LOCAL_DIR"
cd "$LOCAL_DIR"
git remote set-url origin "$CI_REPOSITORY_URL"
git config user.email "[BOT] GitLab Runner <gitlab-ci-runner@gitlab.com:Tim098b/timwens.ink.git>"
git config user.name "GitLab Runner"
git fetch --unshallow --tags origin "$BRANCH"
git checkout "$BRANCH"
only:
- main
But it doesn't appear in the folder it says it would
The issue isn't that the job isn't completing, it's that it's not completing on the server you expect it to
You're expecting your rPi to pick up the job, which is why you're cloning the repo into a specific directory. Your expectation is that when the job finishes, the files are in place in that directory, right?
That's what I am thinking
If you look at line 2 of the job log above though, you can see that your raspberry Pi isn't picking up the job, one of GitLab's shared runner clusters is picking up the job instead. That means your job is completing, but your repository is cloned into a container instead, and the container is discarded when the job completes
this means that your job completes successfully, but immediately discards the container (and thus the repository that it cloned). Since your rPi isn't picking anything up, there is no permanent impact on your rPi, which is why you don't see anything there
You need the gitlab-runner you installed on your raspberry pi to be the only one that picks up this job. That means every time this particular job runs, it would always be picked up by your pi, which means you can rely on your pi to have the changes on it when the job finishes
tags is how you do that. You assign the runner instance on your pi a specific tag, then specify that tag on the job.
hopefully that helps explain what you're seeing and how to fix it
Yep, that "Deploy" tag would be the one you need
so if you added:
tags:
- Deploy
To your job, it should only be picked up by the runner in your UI screenshot there (which I assume is your pi ๐ )
You'll know your pi picks up the job if those first 2 lines of the job logs show your runner name (should also be visible in the same UI as the tag) instead of the saas gitlab.com runners
new errors are good though, now you can troubleshoot from there ๐
It seems to work now, thx!
no problem!