Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications failing with 'HTTP 400' response #106

Closed
fatmcgav opened this issue Apr 13, 2017 · 12 comments
Closed

Notifications failing with 'HTTP 400' response #106

fatmcgav opened this issue Apr 13, 2017 · 12 comments
Assignees
Milestone

Comments

@fatmcgav
Copy link

I'm trying to use Hipchat notifications plugin v2.1.0 with Pipeline, however the notification step is failing.

Jenkins step looks like:

hipchatSend room: 'Jenkins', color: 'RED', message: "Plan Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER} (${env.BLUE_OCEAN_URL})", token: "KgwikF1PEfr69boPcQpbfAVxb25U2TZKQy0w4OQU", textFormat: true

Looking at the Jenkins logs, I can see the following being logged:

WARNING: HipChat post may have failed. ResponseCode: 400, Response: {
  "error": {
    "code": 400,
    "description": "Value {value!r} is not of type {expected_type!r}",
    "expected_type": [
      {
        "type": "null"
      },
      {
        "additionalProperties": true,
        "properties": {
          "activity": {
            "additionalProperties": false,
            "description": "The activity will generate a collapsable card of one line showing the html\nand the ability to maximize to see  all the content.",
            "optional": true,
            "properties": {
              "html": {
                "description": "Html for the activity to show in one line a summary of the action that happened",
                "minLength": 1,
                "type": "string"
              },
              "icon": {
                "optional": true,
                "type": [
                  {
                    "type": "string"
                  },
                  {
                    "additionalProperties": true,
                    "properties": {
                      "url": {
                        "description": "The url where the icon is",
                        "minLength": 1,
                        "type": "string"
                      },
                      "url@2x": {
                        "description": "The url for the icon in retina",
                        "minLength": 1,
                        "optional": true,
                        "type": "string"
                      }
                    },
                    "type": "object"
                  }
                ]
              }
            },
            "type": "object"
          },
          "attributes": {
            "description": "List of attributes to show below the card. Sample {label}:{value.icon} {value.label}",
            "items": {
              "additionalProperties": false,
              "properties": {
                "label": {
                  "maxLength": 50,
                  "minLength": 1,
                  "optional": true,
                  "type": "string"
                },
                "value": {
                  "additionalProperties": false,
                  "properties": {
                    "icon": {
                      "optional": true,
                      "type": [
                        {
                          "type": "string"
                        },
                        {
                          "additionalProperties": true,
                          "properties": {
                            "url": {
                              "description": "The url where the icon is",
                              "minLength": 1,
                              "type": "string"
                            },
                            "url@2x": {
                              "description": "The url for the icon in retina",
                              "minLength": 1,
                              "optional": true,
                              "type": "string"
                            }
                          },
                          "type": "object"
                        }
                      ]
                    },
                    "label": {
                      "description": "The text representation of the value",
                      "minLength": 1,
                      "type": "string"
                    },
                    "style": {
                      "description": "AUI Integrations for now supporting only lozenges",
                      "enum": [
                        "lozenge-success",
                        "lozenge-error",
                        "lozenge-current",
                        "lozenge-complete",
                        "lozenge-moved",
                        "lozenge"
                      ],
                      "minLength": 1,
                      "optional": true,
                      "type": "string"
                    },
                    "url": {
                      "description": "Url to be opened when a user clicks on the label",
                      "minLength": 1,
                      "optional": true,
                      "type": "string"
                    }
                  },
                  "type": "object"
                }
              },
              "type": "object"
            },
            "maxLength": 10,
            "minLength": 1,
            "optional": true,
            "type": "array"
          },
          "description": {
            "optional": true,
            "type": [
              {
                "maxLength": 500,
                "minLength": 0,
                "type": "string"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "format": {
                    "description": "The format that can be html or text",
                    "enum": [
                      "html",
                      "text"
                    ],
                    "minLength": 1,
                    "type": "string"
                  },
                  "value": {
                    "description": "The description in the specific format",
                    "maxLength": 1000,
                    "minLength": 1,
                    "type": "string"
                  }
                },
                "type": "object"
              }
            ]
          },
          "format": {
            "description": "Application cards can be compact (1 to 2 lines) or medium (1 to 5 lines)",
            "enum": [
              "compact",
              "medium"
            ],
            "maxLength": 25,
            "minLength": 1,
            "optional": true,
            "type": "string"
          },
          "icon": {
            "optional": true,
            "type": [
              {
                "type": "string"
              },
              {
                "additionalProperties": true,
                "properties": {
                  "url": {
                    "description": "The url where the icon is",
                    "minLength": 1,
                    "type": "string"
                  },
                  "url@2x": {
                    "description": "The url for the icon in retina",
                    "minLength": 1,
                    "optional": true,
                    "type": "string"
                  }
                },
                "type": "object"
              }
            ]
          },
          "id": {
            "description": "An id that will help HipChat recognise the same card when it is sent multiple times",
            "minLength": 1,
            "type": "string"
          },
          "style": {
            "description": "Type of the card",
            "enum": [
              "file",
              "image",
              "application",
              "link",
              "media"
            ],
            "maxLength": 16,
            "minLength": 1,
            "type": "string"
          },
          "thumbnail": {
            "additionalProperties": true,
            "optional": true,
            "properties": {
              "height": {
                "description": "The original height of the image",
                "optional": true,
                "type": "number"
              },
              "url": {
                "description": "The thumbnail url",
                "maxLength": 250,
                "minLength": 1,
                "type": "string"
              },
              "url@2x": {
                "description": "The thumbnail url in retina",
                "maxLength": 250,
                "minLength": 1,
                "optional": true,
                "type": "string"
              },
              "width": {
                "description": "The original width of the image",
                "optional": true,
                "type": "number"
              }
            },
            "type": "object"
          },
          "title": {
            "description": "The title of the card",
            "maxLength": 500,
            "minLength": 1,
            "type": "string"
          },
          "url": {
            "description": "The url where the card will open",
            "minLength": 1,
            "optional": true,
            "type": "string"
          }
        },
        "type": "object"
      }
    ],
    "field": "card",
    "message": "Value {u'style': u'application', u'title': u'Terraform/k5-jenkins-test', u'url': u'http://ops-jenkins.card.co.uk:8080/job/Terraform/job/k5-jenkins-test/15/', u'format': u'medium', u'activity': {u'html': u'Plan Failed: Terraform/k5-jenkins-test - 15 (null)', u'icon': {u'url': u'https://bit.ly/2ctIstd'}}, u'attributes': [{u'value': {u'style': u'lozenge-success', u'label': u'TEST_COUNTS is not supported in this context'}, u'label': u'Tests Successful'}, {u'value': {u'style': u'lozenge-error', u'label': u'TEST_COUNTS is not supported in this context'}, u'label': u'Tests Failed'}, {u'value': {u'style': u'lozenge-current', u'label': u'TEST_COUNTS is not supported in this context'}, u'label': u'Tests Skipped'}, {u'value': {u'url': u'', u'label': u'Here'}, u'label': u'Test Report'}], u'id': u'7b4758db-c69d-4edc-a9bd-68643dead4af', u'icon': {u'url': u'https://bit.ly/2ctIstd'}} for field 'card' is not of type [{'type': 'null'}, {'additionalProperties': True, 'type': 'object', 'properties': {u'style': {'description': 'Type of the card', 'minLength': 1, 'enum': ['file', 'image', 'application', 'link', 'media'], 'maxLength': 16, 'type': 'string'}, u'description': {'optional': True, 'type': [{'minLength': 0, 'type': 'string', 'maxLength': 500}, {'additionalProperties': False, 'type': 'object', 'properties': {u'value': {'minLength': 1, 'type': 'string', 'description': 'The description in thespecific format', 'maxLength': 1000}, u'format': {'minLength': 1, 'enum': ['html', 'text'], 'type': 'string', 'description': 'The format that can be html or text'}}}]}, u'format': {'description': 'Application cards can be compact (1 to2 lines) or medium (1 to 5 lines)', 'minLength': 1, 'enum': ['compact', 'medium'], 'optional': True, 'maxLength': 25, 'type': 'string'}, u'url': {'minLength': 1, 'type': 'string', 'description': 'The url where the card will open', 'optional': True}, u'title': {'minLength': 1, 'type': 'string', 'description': 'The title of the card', 'maxLength': 500}, u'thumbnail': {'additionalProperties': True, 'optional': True, 'type': 'object', 'properties': {u'url': {'minLength':1, 'type': 'string', 'description': 'The thumbnail url', 'maxLength': 250}, u'width': {'optional': True, 'type': 'number', 'description': 'The original width of the image'}, 'url@2x': {'description': 'The thumbnail url in retina', 'minLength': 1, 'optional': True, 'maxLength': 250, 'type': 'string'}, u'height': {'optional': True, 'type': 'number', 'description': 'The original height of the image'}}}, u'activity': {'description': 'The activity will generate a collapsable card of one line showing the html\\nand the ability to maximize to see  all the content.', 'type': 'object', 'additionalProperties': False, 'optional': True, 'properties': {u'html': {'minLength': 1, 'type': 'string', 'description': 'Html for the activity to show in one line a summary of the action that happened'}, u'icon': {'optional': True, 'type': [{'type': 'string'}, {'additionalProperties': True, 'type': 'object', 'properties': {u'url': {'minLength': 1, 'type': 'string', 'description': 'The url where the icon is'}, 'url@2x': {'minLength': 1, 'type': 'string', 'description': 'The url for the icon in retina', 'optional': True}}}]}}}, u'attributes': {'description': 'List of attributes to show below the card. Sample {label}:{value.icon} {value.label}', 'items': {'additionalProperties': False, 'type': 'object', 'properties': {u'value': {'additionalProperties': False, 'type': 'object', 'properties': {u'url': {'minLength': 1, 'type': 'string', 'description': 'Url to be opened when a user clicks on the label', 'optional': True}, u'style': {'description': 'AUI Integrations for now supporting only lozenges', 'minLength': 1, 'enum': ['lozenge-success', 'lozenge-error', 'lozenge-current', 'lozenge-complete', 'lozenge-moved', 'lozenge'], 'optional': True, 'type': 'string'}, u'label': {'minLength': 1, 'type': 'string', 'description': 'The text representation of the value'}, u'icon': {'optional': True, 'type': [{'type': 'string'}, {'additionalProperties': True, 'type': 'object', 'properties': {u'url': {'minLength': 1, 'type': 'string', 'description': 'The url where the icon is'}, 'url@2x': {'minLength': 1, 'type': 'string', 'description': 'The url for the icon in retina', 'optional': True}}}]}}}, u'label': {'minLength': 1, 'type': 'string', 'optional': True, 'maxLength': 50}}}, 'optional': True, 'maxLength': 10, 'type': 'array', 'minLength': 1}, u'id': {'minLength': 1, 'type': 'string', 'description': 'An id that will help HipChat recognise the same card when it is sent multiple times'}, u'icon': {'optional': True, 'type': [{'type': 'string'}, {'additionalProperties': True, 'type': 'object', 'properties': {u'url': {'minLength': 1, 'type': 'string', 'description': 'The url where the icon is'}, 'url@2x': {'minLength': 1, 'type': 'string', 'description': 'The url for the icon in retina', 'optional': True}}}]}}}]",
    "type": "Bad Request",
    "validation": "type",
    "value": {
      "activity": {
        "html": "Plan Failed: Terraform/k5-jenkins-test - 15 (null)",
        "icon": {
          "url": "https://bit.ly/2ctIstd"
        }
      },
      "attributes": [
        {
          "label": "Tests Successful",
          "value": {
            "label": "TEST_COUNTS is not supported in this context",
            "style": "lozenge-success"
          }
        },
        {
          "label": "Tests Failed",
          "value": {
            "label": "TEST_COUNTS is not supported in this context",
            "style": "lozenge-error"
          }
        },
        {
          "label": "Tests Skipped",
          "value": {
            "label": "TEST_COUNTS is not supported in this context",
            "style": "lozenge-current"
          }
        },
        {
          "label": "Test Report",
          "value": {
            "label": "Here",
            "url": ""
          }
        }
      ],
      "format": "medium",
      "icon": {
        "url": "https://bit.ly/2ctIstd"
      },
      "id": "7b4758db-c69d-4edc-a9bd-68643dead4af",
      "style": "application",
      "title": "Terraform/k5-jenkins-test",
      "url": "http://ops-jenkins.card.co.uk:8080/job/Terraform/job/k5-jenkins-test/15/"
    }
  }
}
Apr 13, 2017 2:22:11 PM org.jenkinsci.plugins.workflow.job.WorkflowRun finish
INFO: Terraform/k5-jenkins-test #15 completed: FAILURE

When searching issues, I found #39, but that's marked as resolved in a much earlier version of the plugin.

Any pointers?

Cheers

@aldaris
Copy link

aldaris commented Apr 13, 2017

Firstly, invalidate your token and generate a new one, as you have just shared this one publicly.

@aldaris
Copy link

aldaris commented Apr 13, 2017

I would suggest to upgrade to 2.1.1 version of the plugin which resolved a few issues around pipeline support.

@fatmcgav
Copy link
Author

@aldaris Apologies, it looks like I am running 2.1.1...

Anything else I can try?

@aldaris
Copy link

aldaris commented Apr 13, 2017

I'm not sure, I will try to test this locally to see if I can reproduce this.

@aldaris
Copy link

aldaris commented Apr 13, 2017

Is this the only hipchatSend command in your pipeline? Tried to reproduce this locally, but it worked just fine for me.

@fatmcgav
Copy link
Author

It's the only one that gets called, based on conditional logic...

		if (exitCode == "1") {
				/* hipchatSend room: 'Jenkins', color: 'RED', message: "Plan Failed: ${env.JOB_NAME} - ${env.BUILD_NUMBER} (${env.BLUE_OCEAN_URL})", token: "[token id]", textFormat: true */
				currentBuild.result = 'FAILURE'
		}
		if (exitCode == "2") {
				stash name: "plan", includes: "plan.out"
				/* hipchatSend room: 'Automation', color: 'GREEN', message: "Plan Awaiting Approval: ${env.JOB_NAME} - ${env.BUILD_NUMBER} (${env.BLUE_OCEAN_URL})", token: "[token id]" */
				try {
						input message: 'Apply Plan?', ok: 'Apply'
						apply = true
				} catch (err) {
						/* hipchatSend room: 'Automation', color: 'YELLOW', message: "Plan Discarded: ${env.JOB_NAME} - ${env.BUILD_NUMBER} (${env.BLUE_OCEAN_URL})", token: "[token id]" */
						apply = false
						currentBuild.result = 'UNSTABLE'
				}
		}

@aldaris
Copy link

aldaris commented Apr 13, 2017

The Test report URL looks to be empty in your message, that may be it. Not sure why would this happen though. Looks like your pipeline build didn't actually have test results associated with it. This may be something that needs to be changed in the DefaultCardProvider just to be absolutely sure that we aren't trying to display test related attributes if they are not even available.

@aldaris
Copy link

aldaris commented Apr 13, 2017

Additionally you may want to make sure that email-ext plugin is installed in your deployment, so that you definitely have access to the TEST_COUNTS macros.

aldaris added a commit that referenced this issue Apr 13, 2017
@fatmcgav
Copy link
Author

@aldaris Ah, yeh, tests...

I'm using the Pipeline to control Terraform... See example here: https://github.com/weareact/terraform/blob/k5-jenkins-test/Jenkinsfile
So strictly speaking, there aren't any tests being executed...

Is that a problem?

@aldaris
Copy link

aldaris commented Apr 13, 2017

It is probably a contributing factor, yes. Hopefully the above commit alleviates that.

Just to be sure: @fatmcgav You did revoke that OAuth2 token you accidentally published in the issue description, right?

@fatmcgav
Copy link
Author

Ok, I'll review the commit and see if i can test locally...

And yeh, i've revoked the token above... 😅

@aldaris
Copy link

aldaris commented Jul 20, 2017

I believe with the commit above and #108 things should be working in your env. Closing this now. Feel free to reopen if the issue is still present in 2.2.0

@aldaris aldaris closed this as completed Jul 20, 2017
@aldaris aldaris self-assigned this Jul 20, 2017
@aldaris aldaris added this to the 2.2.0 milestone Jul 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants