Skip to content

Commit d4d7404

Browse files
committed
tolerate yaml payloads for generic webhooks
1 parent 9c76951 commit d4d7404

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/build/webhook/generic/generic.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/golang/glog"
1111

1212
kapi "k8s.io/kubernetes/pkg/api"
13+
"k8s.io/kubernetes/pkg/util/yaml"
1314

1415
"github.com/openshift/origin/pkg/build/api"
1516
"github.com/openshift/origin/pkg/build/webhook"
@@ -54,7 +55,7 @@ func (p *WebHookPlugin) Extract(buildCfg *api.BuildConfig, secret, path string,
5455
}
5556
}
5657

57-
if req.Body != nil && contentType == "application/json" {
58+
if req.Body != nil && (contentType == "application/json" || contentType == "application/yaml") {
5859
body, err := ioutil.ReadAll(req.Body)
5960
if err != nil {
6061
return nil, envvars, false, err
@@ -65,8 +66,13 @@ func (p *WebHookPlugin) Extract(buildCfg *api.BuildConfig, secret, path string,
6566
}
6667

6768
var data api.GenericWebHookEvent
69+
body, err = yaml.ToJSON(body)
70+
if err != nil {
71+
glog.V(4).Infof("Error converting payload to json %v, but continuing with build", err)
72+
return nil, envvars, true, nil
73+
}
6874
if err = json.Unmarshal(body, &data); err != nil {
69-
glog.V(4).Infof("Error unmarshaling json %v, but continuing", err)
75+
glog.V(4).Infof("Error unmarshalling payload %v, but continuing with build", err)
7076
return nil, envvars, true, nil
7177
}
7278
if len(data.Env) > 0 && trigger.AllowEnv {

0 commit comments

Comments
 (0)