Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

connecteev's avatar

Envoy for local build script?

Can Envoy be used for a local build script instead of a remote server deploy script? ANy examples? I haven't been able to get this to work for some reason or another....variables dont get recognized, and @setup never gets called.


@servers(['web' => 'localhost'])

@setup
    $dir = "/Users/kp/Code/_tmpbuilds/build_" . date('YmdHis')
@endsetup

@story('local')
    clone_repository
@endstory

@task('clone_repository')
    echo "/Users/kp/Code/_tmpbuilds/build_" . date('YmdHis');

    echo "-- Done --"
@endtask

Output:

$ envoy run local
[localhost]: sh: -c: line 5: syntax error near unexpected token `('
[localhost]: sh: -c: line 5: `echo "/Users/kp/Code/_tmpbuilds/build_" . date('YmdHis');'
[✗] This task did not complete successfully on one of your servers.
0 likes
4 replies
bobbybouwmann's avatar

You're using php on the command line. You're mixing things up. So instead you want something like this

@task('clone_repository')
    echo /Users/kp/Code/_tmpbuilds/build_ {{ date('YmdHis') }}
@endtask

This should work.

You don't see anything happening in your @setup method since it's only assigning a variable!

connecteev's avatar

Thanks @bobbybouwmann

#1 your suggestion for the echo on my local Macbook worked: echo /Users/kp/Code/_tmpbuilds/build_ {{ date('YmdHis') }}

Just is a bit strange because this version worked fine (on a remote server) with echo "/Users/kp/Code/_tmpbuilds/build_" . date('YmdHis'); I guess different OS?

#2 Focusing on running this on my local Mac again, How do I set variables? My point with @ setup was that the variables set there are not visible within the @ task

@setup
    $dir = "/Users/kunalpunjabi/Code/_tmpbuilds/build_" . date('YmdHis')
@endsetup

@story('local')
    clone_repository
@endstory

@task('clone_repository')
    echo "mydir:" $dir
    echo "-- Done --"
@endtask

THis outputs:

$ envoy run local
[localhost]: mydir:
[localhost]: -- Done --
connecteev's avatar
connecteev
OP
Best Answer
Level 11

Thanks!

Turns out the answer is that you have to use the blade syntax, like {{ $dir }}

Please or to participate in this conversation.