Jump to content

Webhook triggers return value


Fury22

Recommended Posts

Hi! I am new to Plastic SCM, I've come from Perforce background and I am really glad I found this source control!
I have issues understanding webhook triggers. I have successfully set up webhooks for discord and custom one as well, the shell script triggers properly. I have looked into triggers documentation and blogs as well.
I use Cloud version.

So I have before-checkin trigger launching on my remote webhook server, and it receives and triggers my shell script perfectly. However... despite returning exit code 0 or 1, this does not get to the client checking in. 
I know that the script triggers for 100% - I am logging stuff there.
Basically I wanted to check simply if the comment is empty or not, but even with simple shell script returning always exit 1, literally without any logic(just for testing and learning), the checkin works. I am not sure how I can return this value correctly through the webhook. Any help welcome!

Link to comment
Share on other sites

Yes, I have this same problem. I'm using Cloud, and would like to create a before-mkbranch webhook that will refuse the creation of a branch when criteria aren't met. The docs say that a non-zero output result will block creation, but they don't say what "output result" means in the context of a webhook. Does Plastic parse the body of the webhook response?

Link to comment
Share on other sites

Hi! I have resolved the issue yesterday actually. I used webhook from this github repository: https://github.com/adnanh/webhook. Then I launched the Amazon AWS instance hosting this webhook there. It requires a json setup file. This is how the setup looks to me.
 

Quote

[
    {
        "id": "checkin_verify",
        "execute-command": "checkin_verify.sh",
        "command-working-directory": "/home/ec2-user/plastic_scm",
        "include-command-output-in-response": true,
        "include-command-output-in-response-on-error": true,
        "pass-file-to-command":
        [
            {
                "EnvName": "PLASTIC_COMMAND_INPUT",
                "source": "payload",
                "name": "INPUT"
            }
        ],
        "pass-arguments-to-command":
        [
            {
                "source": "payload", 
                "name": "PLASTIC_COMMENT"
            },
            {
                "source": "payload", 
                "name": "PLASTIC_SHELVE"
            },
            {
                "source": "payload", 
                "name": "PLASTIC_USER"
            }
        ]
    },
    {
        "id": "checkin_notifier",
        "execute-command": "checkin_notifier.sh",
        "command-working-directory": "/home/ec2-user/plastic_scm",
        "include-command-output-in-response": false,
        "include-command-output-in-response-on-error": false,
        "pass-file-to-command":
        [
            {
                "EnvName": "PLASTIC_COMMAND_INPUT",
                "source": "payload",
                "name": "INPUT"
            }
        ],
        "pass-arguments-to-command":
        [
            {
                "source": "payload", 
                "name": "PLASTIC_COMMENT"
            },
            {
                "source": "payload", 
                "name": "PLASTIC_SHELVE"
            },
            {
                "source": "payload", 
                "name": "PLASTIC_USER"
            }
        ]
    }
]

So basically that how I pass those arguments into the shell script. I am saving "INPUT" parameter into the file rather than having it as parameter, because it's a large string and with a bit more files it will crash the shell script because the argument is too long. But I am saving it into txt file and reading from within the shell script. 
Also, the SCM documentation is outdated, some parameters no longer exist, so watch out for those.

As of return parameters, webhook has these two: 
        "include-command-output-in-response": false,
        "include-command-output-in-response-on-error": false,
If the one with the error is set to true, then you can return for example exit 1 from the shell and it will not allow the checkin to pass.
Additionally it will grab whatever you echoed before so for example:

/// IF SOME CONDITION
then 
    echo "Condition failed!
    exit 1
fi

exit 0

this script will print to the client who tries to check stuff in.

Link to comment
Share on other sites

Aha, thanks Fury22, that helped.

Formalizing this for anyone reading in the future: If a webhook returns an HTTP status code other than 200, the trigger will fail, and the body of the HTTP response will be reported to the client verbatim.

cm attribute create FOO
The trigger before-mkatt [before-mkatt] failed. arglebargle.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...