This looks like indentation errors (very important when working with yaml files)
rules and script are separate job keywords. They should not be nested within one another and none should have a - before them. allow_failure is also a keyword and therefore should not use an = but a :.
I also believe that the rules section is evaluated during pipeline/job startup.
This means export ing the variable you are acting on within the script will not cause the rule to be executed. That variable would have to be passed in via CI/CD variables, or within the variables: section of that job (or defaults).
I recommend looking into a dynamic pipeline, parent-child pipelines, or manual (API) triggering of a pipeline where you can pass the variable with its value into the job.
I entered the yml incorrectly. I edited the original post now with the correct version. Either way, I would have expected something else than a syntax error for the allow_failure part. I could use any predefined variable there and still have the error pop up.
Thanks for the reply.
I may have edited my post after you saw it originally. The syntax error is due to the equals sign after allow_failure. That is a keyword and should have a colon instead of an equal sign.
I tried adding a when: always instead of the allow_failure part and it worked. Also tried having them both (if, when and then allow_failure) and had the same error related to the allow_failure part.