Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41503

JSON Schema issue: mapArgumentValue not accepting null

    XMLWordPrintable

Details

    Description

      Arguments with

      { isLiteral: true, "value": null }

      fail schema validation.

      I think this needs to allow null values: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-api/src/main/resources/ast-schema.json#L50 or alternately, don't include those args in the JSON during conversion? Not sure if they are necessarily equivalent.

      Took this valid pipeline:

      pipeline {
          agent {
              docker {
                  image "httpd:2.4.12"
                  args null
              }
          }
          stages {
              stage("foo") {
                  steps {
                      sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
                      sh 'echo "The answer is 42"'
                  }
              }
          }
      }
      

      which converts to the corresponding JSON, that no longer passes schema validation due to agent docker args null value:

      {
          "pipeline": {
              "agent": {
                  "type": "docker",
                  "arguments": [
                      {
                          "key": "image",
                          "value": {
                              "isLiteral": true,
                              "value": "httpd:2.4.12"
                          }
                      },
                      {
                          "key": "args",
                          "value": {
                              "isLiteral": true,
                              "value": null
                          }
                      }
                  ]
              },
              "stages": [
                  {
                      "name": "foo",
                      "branches": [
                          {
                              "name": "default",
                              "steps": [
                                  {
                                      "name": "sh",
                                      "arguments": [
                                          {
                                              "key": "script",
                                              "value": {
                                                  "isLiteral": true,
                                                  "value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
                                              }
                                          }
                                      ]
                                  },
                                  {
                                      "name": "sh",
                                      "arguments": [
                                          {
                                              "key": "script",
                                              "value": {
                                                  "isLiteral": true,
                                                  "value": "echo \"The answer is 42\""
                                              }
                                          }
                                      ]
                                  }
                              ]
                          }
                      ]
                  }
              ]
          }
      }
      

      Attachments

        Issue Links

          Activity

            kzantow Keith Zantow created issue -
            kzantow Keith Zantow made changes -
            Field Original Value New Value
            Description Arguments with _{ isLiteral: true, "value": null }_ fail schema validation.

            I think this needs to allow null values: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-api/src/main/resources/ast-schema.json#L50

            Took this valid pipeline:

            {code}
            pipeline {
                agent {
                    docker {
                        image "httpd:2.4.12"
                        args null
                    }
                }
                stages {
                    stage("foo") {
                        steps {
                            sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
                            sh 'echo "The answer is 42"'
                        }
                    }
                }
            }
            {code}

            which converts to the corresponding JSON, that no longer passes schema validation due to agent docker args null value:

            {code}
            {
                "pipeline": {
                    "agent": {
                        "type": "docker",
                        "arguments": [
                            {
                                "key": "image",
                                "value": {
                                    "isLiteral": true,
                                    "value": "httpd:2.4.12"
                                }
                            },
                            {
                                "key": "args",
                                "value": {
                                    "isLiteral": true,
                                    "value": null
                                }
                            }
                        ]
                    },
                    "stages": [
                        {
                            "name": "foo",
                            "branches": [
                                {
                                    "name": "default",
                                    "steps": [
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "echo \"The answer is 42\""
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
            {code}
            Arguments with { isLiteral: true, "value": null } fail schema validation.

            I think this needs to allow null values: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-api/src/main/resources/ast-schema.json#L50

            Took this valid pipeline:

            {code}
            pipeline {
                agent {
                    docker {
                        image "httpd:2.4.12"
                        args null
                    }
                }
                stages {
                    stage("foo") {
                        steps {
                            sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
                            sh 'echo "The answer is 42"'
                        }
                    }
                }
            }
            {code}

            which converts to the corresponding JSON, that no longer passes schema validation due to agent docker args null value:

            {code}
            {
                "pipeline": {
                    "agent": {
                        "type": "docker",
                        "arguments": [
                            {
                                "key": "image",
                                "value": {
                                    "isLiteral": true,
                                    "value": "httpd:2.4.12"
                                }
                            },
                            {
                                "key": "args",
                                "value": {
                                    "isLiteral": true,
                                    "value": null
                                }
                            }
                        ]
                    },
                    "stages": [
                        {
                            "name": "foo",
                            "branches": [
                                {
                                    "name": "default",
                                    "steps": [
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "echo \"The answer is 42\""
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
            {code}
            kzantow Keith Zantow made changes -
            Description Arguments with { isLiteral: true, "value": null } fail schema validation.

            I think this needs to allow null values: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-api/src/main/resources/ast-schema.json#L50

            Took this valid pipeline:

            {code}
            pipeline {
                agent {
                    docker {
                        image "httpd:2.4.12"
                        args null
                    }
                }
                stages {
                    stage("foo") {
                        steps {
                            sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
                            sh 'echo "The answer is 42"'
                        }
                    }
                }
            }
            {code}

            which converts to the corresponding JSON, that no longer passes schema validation due to agent docker args null value:

            {code}
            {
                "pipeline": {
                    "agent": {
                        "type": "docker",
                        "arguments": [
                            {
                                "key": "image",
                                "value": {
                                    "isLiteral": true,
                                    "value": "httpd:2.4.12"
                                }
                            },
                            {
                                "key": "args",
                                "value": {
                                    "isLiteral": true,
                                    "value": null
                                }
                            }
                        ]
                    },
                    "stages": [
                        {
                            "name": "foo",
                            "branches": [
                                {
                                    "name": "default",
                                    "steps": [
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "echo \"The answer is 42\""
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
            {code}
            Arguments with { isLiteral: true, "value": null } fail schema validation.

            I think this needs to allow null values: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-api/src/main/resources/ast-schema.json#L50 or alternately, don't include those args in the JSON during conversion? Not sure if they are necessarily equivalent.

            Took this valid pipeline:

            {code}
            pipeline {
                agent {
                    docker {
                        image "httpd:2.4.12"
                        args null
                    }
                }
                stages {
                    stage("foo") {
                        steps {
                            sh 'cat /usr/local/apache2/conf/extra/httpd-userdir.conf'
                            sh 'echo "The answer is 42"'
                        }
                    }
                }
            }
            {code}

            which converts to the corresponding JSON, that no longer passes schema validation due to agent docker args null value:

            {code}
            {
                "pipeline": {
                    "agent": {
                        "type": "docker",
                        "arguments": [
                            {
                                "key": "image",
                                "value": {
                                    "isLiteral": true,
                                    "value": "httpd:2.4.12"
                                }
                            },
                            {
                                "key": "args",
                                "value": {
                                    "isLiteral": true,
                                    "value": null
                                }
                            }
                        ]
                    },
                    "stages": [
                        {
                            "name": "foo",
                            "branches": [
                                {
                                    "name": "default",
                                    "steps": [
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "cat /usr/local/apache2/conf/extra/httpd-userdir.conf"
                                                    }
                                                }
                                            ]
                                        },
                                        {
                                            "name": "sh",
                                            "arguments": [
                                                {
                                                    "key": "script",
                                                    "value": {
                                                        "isLiteral": true,
                                                        "value": "echo \"The answer is 42\""
                                                    }
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            }
            {code}
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            abayer Andrew Bayer added a comment - PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/122
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "PR #122 (Web Link)" [ 15481 ]

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-api/src/main/resources/ast-schema.json
            pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Converter.groovy
            pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
            pipeline-model-definition/src/test/resources/json/jsonSchemaNull.json
            pipeline-model-definition/src/test/resources/jsonSchemaNull.groovy
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/6e518e32c311d5f80458a1911cbbea6b4da87783
            Log:
            [FIXED JENKINS-41503] Allow null values in JSON

            Also required changing org.json -> Jackson conversion to go through a
            string rather than use a mapper due to the mapper not liking nulls at
            all.

            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-api/src/main/resources/ast-schema.json pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/Converter.groovy pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java pipeline-model-definition/src/test/resources/json/jsonSchemaNull.json pipeline-model-definition/src/test/resources/jsonSchemaNull.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/6e518e32c311d5f80458a1911cbbea6b4da87783 Log: [FIXED JENKINS-41503] Allow null values in JSON Also required changing org.json -> Jackson conversion to go through a string rather than use a mapper due to the mapper not liking nulls at all.
            abayer Andrew Bayer made changes -
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Resolved [ 5 ]
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.
            bitwiseman Liam Newman made changes -
            Status Resolved [ 5 ] Closed [ 6 ]

            People

              abayer Andrew Bayer
              kzantow Keith Zantow
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: