diff --git a/pkg/oc/cli/cmd/newbuild.go b/pkg/oc/cli/cmd/newbuild.go index e257c1e40be9..596b995c8020 100644 --- a/pkg/oc/cli/cmd/newbuild.go +++ b/pkg/oc/cli/cmd/newbuild.go @@ -114,6 +114,7 @@ func NewCmdNewBuild(name, baseName string, f *clientcmd.Factory, in io.Reader, o cmd.Flags().StringSliceVar(&config.DockerImages, "docker-image", config.DockerImages, "Name of a Docker image to use as a builder.") cmd.Flags().StringSliceVar(&config.Secrets, "build-secret", config.Secrets, "Secret and destination to use as an input for the build.") cmd.Flags().StringVar(&config.SourceSecret, "source-secret", "", "The name of an existing secret that should be used for cloning a private git repository.") + cmd.Flags().StringVar(&config.PushSecret, "push-secret", "", "The name of an existing secret that should be used for pushing to a Docker repository if --to-docker and --to are set.") cmd.Flags().StringVar(&config.Name, "name", "", "Set name to use for generated build artifacts.") cmd.Flags().StringVar(&config.To, "to", "", "Push built images to this image stream tag (or Docker image repository if --to-docker is set).") cmd.Flags().BoolVar(&config.OutputDocker, "to-docker", false, "If true, have the build output push to a Docker repository.") diff --git a/pkg/oc/generate/cmd/newapp.go b/pkg/oc/generate/cmd/newapp.go index 9c89319d6de8..cf042766f0ce 100644 --- a/pkg/oc/generate/cmd/newapp.go +++ b/pkg/oc/generate/cmd/newapp.go @@ -106,6 +106,7 @@ type AppConfig struct { AllowSecretUse bool SourceSecret string + PushSecret string AllowNonNumericExposedPorts bool SecretAccessor app.SecretAccessor @@ -906,6 +907,15 @@ func (c *AppConfig) Run() (*AppResult, error) { } } } + if len(c.PushSecret) > 0 { + for _, obj := range objects { + if bc, ok := obj.(*buildapi.BuildConfig); ok { + glog.V(4).Infof("Setting push secret for build config to: %v", c.SourceSecret) + bc.Spec.Output.PushSecret = &kapi.LocalObjectReference{Name: c.PushSecret} + break + } + } + } return &AppResult{ List: &kapi.List{Items: objects}, diff --git a/test/cmd/newapp.sh b/test/cmd/newapp.sh index d5958eb3c828..a728fbd5f8fd 100755 --- a/test/cmd/newapp.sh +++ b/test/cmd/newapp.sh @@ -68,6 +68,8 @@ os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cake os::cmd::expect_success_and_text 'oc new-app -f examples/quickstarts/cakephp-mysql.json --source-secret=mysecret -o yaml' 'name: mysecret' os::cmd::expect_success 'oc new-app https://github.com/openshift/cakephp-ex --source-secret=mysecret' os::cmd::expect_success 'oc delete all --selector="label=cakephp-ex"' +# setting push secret via the --push-secret flag +os::cmd::expect_success_and_text 'oc new-build https://github.com/openshift/cakephp-ex --push-secret=mynewsecret -o yaml' 'name: mynewsecret' # check label creation