Skip to content
Snippets Groups Projects
Commit 0b1efbf0 authored by Lucas Jenss's avatar Lucas Jenss
Browse files

Change unregister command to accept runner name

parent 6e269af5
No related branches found
No related tags found
No related merge requests found
package commands
import (
"fmt"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/common"
"gitlab.com/gitlab-org/gitlab-ci-multi-runner/network"
"os"
......@@ -49,6 +50,20 @@ func (c *configOptions) touchConfig() error {
return nil
}
func (c *configOptions) RunnerByName(name string) (*common.RunnerConfig, error) {
if c.config == nil {
return nil, fmt.Errorf("Config has not been loaded")
}
for _, runner := range c.config.Runners {
if runner.Name == name {
return runner, nil
}
}
return nil, fmt.Errorf("Could not find a runner with the name '%s'", name)
}
func init() {
configFile := os.Getenv("CONFIG_FILE")
if configFile == "" {
......
......@@ -12,18 +12,29 @@ type UnregisterCommand struct {
configOptions
common.RunnerCredentials
network common.Network
Name string `toml:"name" json:"name" short:"n" long:"name" description:"Name of the runner you wish to unregister"`
}
func (c *UnregisterCommand) Execute(context *cli.Context) {
userModeWarning(false)
if !c.network.DeleteRunner(c.RunnerCredentials) {
log.Fatalln("Failed to delete runner")
}
err := c.loadConfig()
if err != nil {
log.Warningln(err)
log.Fatalln(err)
return
}
if len(c.Name) > 0 {
runnerConfig, err := c.RunnerByName(c.Name)
if err != nil {
log.Fatalln(err)
return
}
c.RunnerCredentials = runnerConfig.RunnerCredentials
}
if !c.network.DeleteRunner(c.RunnerCredentials) {
log.Fatalln("Failed to delete runner", c.Name)
return
}
......
......@@ -288,22 +288,32 @@ gitlab-runner verify --delete
### gitlab-runner unregister
This command allows to unregister one of the registered runners. It expects to
enter a full URL and the runner's token. First get the runner's details by
This command allows to unregister one of the registered runners. It expects either
a full URL and the runner's token, or the runner's name. First get the runner's details by
executing `gitlab-runner list`:
```bash
test-runner Executor=shell Token=t0k3n URL=http://gitlab.example.com/ci/
```
Then use this information to unregister it, using the following command.
Then use this information to unregister it, using one of the following commands.
>**Warning:**
This operation cannot be undone, it will update the configuration file, so
make sure to have a backup of `config.toml` before executing it.
#### By URL and token:
```bash
gitlab-runner unregister --url http://gitlab.example.com/ci/ --token t0k3n
```
#### By name:
> **Note:** If there is more than one runner with the given name, only the first one will be removed
```bash
gitlab-runner unregister -u http://gitlab.example.com/ci/ -t t0k3n
gitlab-runner unregister --name test-runner
```
## Service-related commands
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment