diff --git a/README.md b/README.md index d6dfcbf8..2f91605f 100644 --- a/README.md +++ b/README.md @@ -430,6 +430,8 @@ The `--release_branch` specifies the value of the ***release_branch_prefix*** at The `create_gitops_prs` tool will query all `gitops` targets which have set the ***deploy_branch*** attribute (see [k8s_deploy](#k8s_deploy)) and the ***release_branch_prefix*** attribute value that matches the `release_branch` parameter. +In case you need to specify a custom Bazel flag during the pull request process, you can add one `--bazel_flag` such as `--bazel_flag --config=ci` or multiple such as `--bazel_flag --config=ci --bazel_flag --color=no`. + The all discovered `gitops` targets are grouped by the value of ***deploy_branch*** attribute. The one deployment branch will accumulate the output of all corresponding `gitops` targets. For example, we define two deployments: grafana and prometheus. Both deployments share the same namespace. The deployments a grouped by namespace. diff --git a/gitops/gitops.bzl b/gitops/gitops.bzl index 6627e0c1..b5ef5f7c 100644 --- a/gitops/gitops.bzl +++ b/gitops/gitops.bzl @@ -15,6 +15,8 @@ def __create_gitops_prs_impl(ctx): executables = src_by_train[deployment_branch] for exe in executables: params += "--resolved_binary {}:{} ".format(deployment_branch, exe.short_path) + if ctx.attr.bazel_flag: + params += "--bazel_flag {} ".format(ctx.attr.bazel_flag) for exe in trans_img_pushes: params += "--resolved_push {} ".format(exe.files_to_run.executable.short_path) if ctx.attr.release_branch: diff --git a/gitops/prer/create_gitops_prs.go b/gitops/prer/create_gitops_prs.go index b7b31036..e73835e1 100644 --- a/gitops/prer/create_gitops_prs.go +++ b/gitops/prer/create_gitops_prs.go @@ -52,6 +52,7 @@ func (i *SliceFlags) Set(value string) error { var ( releaseBranch = flag.String("release_branch", "master", "filter gitops targets by release branch") bazelCmd = flag.String("bazel_cmd", "tools/bazel", "bazel binary to use") + bazelFlags SliceFlags workspace = flag.String("workspace", "", "path to workspace root") repo = flag.String("git_repo", "", "git repo location") gitMirror = flag.String("git_mirror", "", "git mirror location, like /mnt/mirror/bitbucket.tubemogul.info/tm/repo.git for jenkins") @@ -77,6 +78,7 @@ var ( ) func init() { + flag.Var(&bazelFlags, "bazel_flag", "bazel flag to pass during gitops phase. Can be specified multiple times. Default is empty") flag.Var(&gitopsKind, "gitops_dependencies_kind", "dependency kind(s) to run during gitops phase. Can be specified multiple times. Default is 'k8s_container_push'") flag.Var(&gitopsRuleName, "gitops_dependencies_name", "dependency name(s) to run during gitops phase. Can be specified multiple times. Default is empty") flag.Var(&gitopsRuleAttr, "gitops_dependencies_attr", "dependency attribute(s) to run during gitops phase. Use attribute=value format. Can be specified multiple times. Default is empty") @@ -266,7 +268,20 @@ func main() { exec.Mustex("", bin) } else { log.Println("target", target, "is not a file, running as a command") - exec.Mustex("", *bazelCmd, "run", target) + + args := []string{"run"} + + if len(bazelFlags) > 0 { + for _, bazelFlag := range bazelFlags { + bazelFlagArgs := strings.Split(bazelFlag, " ") + + args = append(args, bazelFlagArgs...) + } + } + + args = append(args, target) + + exec.Mustex("", *bazelCmd, args...) } } }()