Support the ongoing development of Laravel.io →
posted 2 years ago
Forge
Last updated 2 years ago.
0

Make sure you are using the forge variable in the deployment script like this: $FORGE_VAR_{param}

I ran this deployment trigger: https://forge.laravel.com/servers/XXX/sites/XXX/deploy/http?token=XXX&name=durgesh

Used it like this in my deployment script: echo "This is my env variable: " $FORGE_VAR_NAME; (Note: my query param is name. If your query param name is xyz, forge variable will be $FORGE_VAR_XYZ)

Output: This is my env variable: durgesh

https://pasteboard.co/q09o7VLKcXiK.png

Last updated 2 years ago.
0

Thank you for the quick response. It's strange because that is exactly what I did ($FORGE_VAR_XYZ).

To set the context a bit, I'm trying to dynamically set the pull branch within the deployment script. I'm using curl to send a GET request, and my branch value has a / in it (e.g user/feature-1). The GET deploy URL is "${Trigger URL}&branch=${Branch name}", I verified within my CICD that the url is correct (in that the values are injected correctly). Now, when the deployment is triggered, and I inspect the echo in the logs, the $FORGE_VAR_BRANCH is empty.

Did you send a POST in your deployment trigger?

0

This seems weird. I just tried passing a branch to my deployment script and was able to get the value in a variable.

My trigger: https://forge.laravel.com/servers/XXX/sites/XXX/deploy/http?token=XXX&branch=sprints/sprint-1

Deployment script:

echo "Branch: $FORGE_VAR_BRANCH"

Deployment log:

Mon 25 Apr 2022 03:19:44 PM UTC
Branch: sprints/sprint-1

Please share your deployment code and cURL function.

BTW I'm using the normal GET method by directly visiting the URL in the browser.

Last updated 2 years ago.
0
Solution selected by @howlowck

Thanks. I removed the curl request within the CICD out of the equation and did a browser GET request like you did with a ${URL}&branch=feature/feature-1.

Here is my deploy code:

echo "---- begin echo ----"
echo "branch is $FORGE_ENV_BRANCH"
echo "---- end echo ----"

And here is the resulting log:

Tue Apr 26 03:06:44 UTC 2022
---- begin echo ----
branch is 
---- end echo ----
0

It should be $FORGE_VAR_BRANCH and not $FORGE_ENV_BRANCH !

0

Thanks @dwebpixel 🤦‍♂️ That fixed the browser requested GET; I was able to get the value in the deployment script. However when I tried using my curl command in GitHub Actions (simply curl ${URL}&branch=feature/feature-1). I'm still getting empty values.

Regardless, at least I know now it's not on Forge's side. I'll dig more on the curl/GH Actions side. Thanks again!

0

If you are triggering the request from the Laravel app, you can simply use the in-built HTTP client it provides to call your request.

$response = Http::get('https://forge.laravel.com/servers/XXX/sites/XXX/deploy/http', [
    'token' => 'XXX',
    'branch' => 'feature/feature-1',
]);

Ref: https://laravel.com/docs/9.x/http-client

0

Thanks @dwebpixel for your help. I'm using GitHub Actions inline to call the trigger URL with a curl command. I figured out what I was doing wrong.

I was doing curl ${TRIGGER_URL}&branch=${BRANCH}, without quotes. & is a special character in bash. So not only was branch query string not set, I was making the entire curl call asynchronous.

After wrapping the URL in quotes (i.e. curl "${TRIGGER_URL}&branch=${BRANCH}"), I was able to correctly see the value in my deploy script log.

Thanks again for your attention and help!

dwebpixel, jacob4him liked this reply

2

Sign in to participate in this thread!

Eventy

Your banner here too?

howlowck howlowck Joined 22 Dec 2013

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.