Skip to content

Commit

Permalink
Allow passing variables to pipeline create
Browse files Browse the repository at this point in the history
  • Loading branch information
egegunes committed May 1, 2020
1 parent 22fed94 commit 520f4d9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ group/project2 master 99814019 01 Dec 19 21:32 +0000 running
$ gitlabci pipeline create group/project master
```

#### Create pipeline with overriding variables

```
$ gitlabci pipeline create group/project master -e BUILD_TARGET=staging
```

### Environment Variables

#### List variables
Expand Down
18 changes: 17 additions & 1 deletion cmd/pipeline_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package cmd
import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/xanzy/go-gitlab"
)

var env []string

func init() {
pipelineCmd.AddCommand(createCmd)
createCmd.Flags().StringSliceVarP(&env, "variable", "e", []string{}, "Override environment variables. KEY=VALUE")
}

var createCmd = &cobra.Command{
Expand All @@ -24,7 +28,19 @@ var createCmd = &cobra.Command{
pid := args[0]
ref := args[1]

opts := &gitlab.CreatePipelineOptions{Ref: gitlab.String(ref)}
var variables []*gitlab.PipelineVariable

for _, variable := range env {
v := strings.Split(variable, "=")

variables = append(variables, &gitlab.PipelineVariable{
Key: v[0],
Value: v[1],
VariableType: "env_var",
})
}

opts := &gitlab.CreatePipelineOptions{Ref: gitlab.String(ref), Variables: variables}
pipeline, _, err := git.Pipelines.CreatePipeline(pid, opts)
if err != nil {
fmt.Fprintf(os.Stderr, "couldn't create pipeline: %v\n", err)
Expand Down

0 comments on commit 520f4d9

Please sign in to comment.