Runner is paused and will not receive any new jobs - continuous-integration

I recently install the gitlab-ruuner in a machine and register a specific runner manually with a registration token which obtained from CI/CD Setting/runner page for my repository by :
sudo gitlab-runner register
I start it by :
sudo -s gitlab-runner start
and output :
Runtime platform arch=amd64 os=linux pid=14558 revision=f100a208 version=11.6.0
The CI pipeline stuck in pending mode and requires a active runner assigned to it. How can I activate the runner?

I solved my problem. First I forgot to do sudo gitlab-runner run and after that I changed the config.toml. Specifically I turned privilege mode to true. And finally in the runner edit page, turn on the run untagged jobs option

If your CI/CD job is pending, saying This job is stuck, because you don't have any active runners that can run this job. Go to Runners page., try restarting your gitlab runner:
$ sudo gitlab-runner stop
$ sudo gitlab-runner start
If it is still not working, then try checking, if not yet, Run untagged jobs as below for your CI/CD runner, which by default is unchecked.

Related

Jenkins - Local checkout - Enable using script console

I am encountering below error. I am able to set the property using System.setProperty("hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT", "true")
However, the issue still persists. Any pointers?
ERROR: Checkout of Git remote '<path to project folder>' aborted
because it references a local directory, which may be insecure.
You can allow local checkouts anyway by setting the system property
'hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT' to true.
I found the info I needed and propably helps you too in
https://issues.jenkins.io/browse/JENKINS-68571:
So, follow these steps:
$ sudo systemctl stop jenkins
$ sudo systemctl edit jenkins
[Service]
Environment="JAVA_OPTS=-Dhudson.model.DirectoryBrowserSupport.CSP= -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
$ sudo systemctl restart jenkins
As per https://issues.jenkins.io/browse/JENKINS-68571:
it seems the System Property is read during initialization, thus changing it in Script Console does not change it.
In Script console use property on class directly:
hudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT = true
Note that neither the System Property nor the class property persist across restarts.
A persistent solution depends on how you installed / start Jenkins.
If you are running via java -jar ..., add the system property there (java -Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true -jar ...).
Or, if you installed it using your systems package manager and your system is using systemd:
$ sudo systemctl edit jenkins
[Service]
Environment="JAVA_OPTS=-Dhudson.plugins.git.GitSCM.ALLOW_LOCAL_CHECKOUT=true"
$ sudo systemctl restart jenkins

Testing gitlab-runner run command in a separate shell?

Context
While testing the functions of an installation script that automatically installs and runs GitLab and GitLab runners, I experienced some difficulties running the GitLab runner in the background an proceeding with the tests. (My intention is to simply run the runner in the background, and then to run a few tests that verify the service behaves as expected). However, when my test executes the function that executes the sudo gitlab-runner run command, the test hangs, waiting on the service to stop, (but the service should not stop).
Function
# Run GitLab runner service
run_gitlab_runner_service() {
run_command=$(sudo gitlab-runner run &)
echo "service is running"
}
The output of the test is:
Configuration loaded builds=0 7/7
And then the cursor just keeps blinking while the last runner is successfully awaiting instructions.
Test Code
#test "Test if the GitLab Runner CI service is running correctly." {
run_service_output=$(run_gitlab_runner_service)
EXPECTED_OUTPUT="service is running"
assert_equal "$run_service_output" "$EXPECTED_OUTPUT"
}
However, when inspecting the regular output of the sudo gitlab-runner run command, I observe that it starts a new line/shell/something without asking. For example:
(base) name#name:~$ sudo gitlab-runner run &
[1] 84799
(base) name#name:~$ Runtime platform arch=amd64 os=linux pid=84800 revision=8925d9a0 version=14.1.0
Starting multi-runner from /etc/gitlab-runner/config.toml... builds=0
Running in system-mode.
Configuration loaded builds=0
listen_address not defined, metrics & debug endpoints disabled builds=0
[session_server].listen_address not defined, session endpoints disabled builds=0
basically, the output (base) name#name:~$ Runtime platform arch=amd64 should never stop (until manually terminated), so I think the test is waiting on that shell/output to complete.
Note
For completeness, I do not type the (base) name#name:~$ Runtime platform arch=amd64 .. output, that somehow is pushed to the terminal in the new line some how. I do not know exactly why this isn't just under the previous/original (base) name#name:~$ that ran the sudo gitlab-runner run & command.
Question
How can I ensure the function and test proceed after starting the gitlab-runner run service?
I think you should use a slightly different syntax in order to run gitlab-runner in background
# Run GitLab runner service
run_gitlab_runner_service() {
( run_command="$(sudo gitlab-runner run)" ) &
echo "service is running"
}
A solution was found by redirecting the output of the command to /dev/null.
Code
# Run GitLab runner service
run_gitlab_runner_service() {
output=$(nohup sudo gitlab-runner run &>/dev/null &)
echo "service is running"
}

Run macOS Test Cases on the Jenkins Pipeline

Hi I have an macOS Application which needs to be configured for CI/CD purpose on the Jenkins.
I need to run the test cases before making the application available for the distribution or before creating a package file.
I am using the below mentioned command
xcodebuild -workspace xxx.xcworkspace -sdk macosx11.3 -scheme xxx -destination "platform=OS X,arch=x86_64" clean test
when I execute this command in the Jenkins it throws me an error
ERROR: The test runner encountered an error (Failed to establish communication with the test runner. If you believe this error represents a bug, please attach the result bundle at /Users/ec2-user/Library/Developer/Xcode/DerivedData/xxx-gkolnyonjdnyixfknefsjvbsyzia/Logs/Test/Run-xxx-2021.05.24_11-58-07-+0000.xcresult. (Underlying Error: Couldn’t communicate with a helper application. Try your operation again. If that fails, quit and relaunch the application and try again. The connection to service on pid 0 named com.apple.testmanagerd.control was invalidated.))
I need to make use of macOS itself to run as a simulator. As Jenkins runs as a Daemon on the ec-2 instance.
NOTE: NOT USING XCODE PLUGIN TO EXECUTE MY COMMANDS
Please help!!!
My MacOS system was a slave and I was running my scripts through the Linux server.
macOS was connected using the SSH earlier then this authentication method was required to be changed to access the UI of the Mac
Test cases running now
Based on observation, macOS Big Sur, Monterey, and probably subsequent versions no longer allow tests to be run through a SSH session. By changing the way Jenkins controller connects to the slave, you can prevent the command from being run through SSH.
The first way, Jenkins built-in, to do this and easiest is to use the JNLP method for agent communication. This will involve running a Jenkins agent on the slave machine that communicates with the Jenkins controller. In the end, the agent on the machine is running the test command rather than through a SSH session.
The second way is to build your own agent. It could be as simple as a file change trigger leading to a script executing. This is only necessary if for some reason the Jenkins slave is not able to connect to the Jenkins controller due to some networking constraints.

Permissions to run docker container on self-hosted windows azure devops agent

In an azure devops build pipeline running on a self-hosted windows agent, I am trying to execute a tool that run a docker container.
Unfortunately I get this error :
Failed to start: failed to create container: Error response from daemon: CreateFile c:\Users\BUILDAGENT\.aerokube\selenoid: Access is denied.
The build agent is configured with its own windows local user "BUILDAGENT", so he has permissions on the C:\Users\BUILDAGENT\ folder
Looking at the process manager, I see that except com.docker.service, the others docker processes are running with the user that launched the Docker Desktop (my coworker).
If I restart windows and relaunch docker myself, the settings selected by my coworker ("Disk Image Location" for instance), are not restored...
Is there a way to make docker run as a daemon on startup with a specific user (service or system user, but not mine or my coworker) ?
Once this is done I guess I just have to give permissions for that specific user on the C:\Users\BUILDAGENT\ folder to solve my issue, right ?
Update :
I added my BUILDAGENT user in docker-users group, and it solves the permission issue, but I still would like to run docker as a service, instead of login as my local user to launch it with its GUI...
but I still would like to run docker as a service, instead of login as my local user to launch it with its GUI
You could try to create a task scheduler to run docker with that specific user when your PC starts.
Please check this thread How to create an automated task using Task Scheduler on Windows 10 for some more details.
In this case, docker will start automatically every time you start your computer.

Un-register gitlab-runner on Ubuntu not working

I'm trying to unregister gitlab-runner on EC2 instance (Ubuntu machine) with the following command:
sudo gitlab-runner --debug unregister --token [RUNNER-TOKEN] --url [RUNNER-URL]
and I'm getting following error:
Runtime platform arch=amd64 os=linux pid=2374 revision=6fbc7474 version=13.1.1
Checking runtime mode GOOS=linux uid=0
Running in system-mode.
Dialing: tcp gitlab.com:443 ...
ERROR: Unregistering runner from GitLab forbidden runner=xv2Ng6Tc
FATAL: Failed to unregister runner
Make sure that you're using the entire SHA, not the partial one listed on the Gitlab CI runners list.
This can be found by running sudo gitlab-runner list on the machine with the runner installed.
If you've already removed the runner in the gitlab runners page, it will still be present on the gitlab-runner machine (check with the command sudo gitlab-runner list).
You can then unregister it from the config.toml using the command:
gitlab-runner verify --delete
Or manually, by running:
sudo gitlab-runner stop
sudo vi /etc/gitlab-runner/config.toml # update the runners section
sudo gitlab-runner start
For MacOS and Ubuntu
If you have already removed it from the Runners section in your project settings then you are no longer be able to unregister with command. Then what you can do is to delete them from your host as below:
gitlab-runner verify --delete
This will remove all the unregistered/removed runners from your host machine and will update config.toml file.
If you haven't removed it from Runners section in your project settings(Settings -> CI/CD -> Runners), then you can unregister it from your host like below:
gitlab-runner unregister runner_id/name
or unregister all runners,
gitlab-runner unregister --all-runners
Hope this will help to somebody. cheers !!!
I experienced the same issue when I tried to remove a runner that was removed directly from Gitlab settings of the project.
It seems that "Remove runner"'s button removes the runner from Gitlab but not from your gitlab-runner, which is absolutely fine since I don't want Gitlab to mess up to my on-premise gitlab-runner.
In order to fix that, I stopped the gitlab-runner service, removed the runner directly from the config file (it is usually located in /etc/gitlab-runner/config.toml) and started the service again.
I hope I could help you ;)
I ran into the same issue. I had to enter the right token in the config.toml file and boom, it worked: See this guide for more information: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4919. This solution is specifically for Windows, but can be applicable to Ubuntu as well.
If someone is still struggling with this like me, then here is something from docs: https://docs.gitlab.com/runner/commands/#gitlab-runner-unregister
gitlab-runner unregister --url http://gitlab.example.com/ --token <full_token_from_etc/gitlab-runner/config.toml>

Resources