Command not found

I’ve got a monorepo where each folder is a separate set of code and tests, so while I was able to get run a very basic config.yml without any trouble, I really need some dynamic config eventually. None of the split-config/config-splitting orbs seem to work as advertised (or I’m doing it wrong), so I wanted to try something simpler, but I’m struggling to get reusable commands and persistent workspaces working.

Following circleci’s examples and tutorials, I was thinking it would be nice if I could put the attach_workspace steps in a command for reuse, but I’m getting ‘command not found’ when I try to do that.

So my current config looks something like this:

           - attach_workspace
                at: /tmp/workspace
           - run: #(check if that worked, copied directly from circle example)

            - image: the_image

    first_job: #(this one works)
        - run: #setup some stuff
        - persist_to_workspace #this seems to work correctly
    second_job: # (doesn't work)
       executor: docker-executor
           - run: downstream #(command that it says it can't find, which is defined right at the top)
           - run: my tests #(it never gets this far)

Is it impossible to do it this way? I’d really like to take advantage of reusable commands, but if they don’t work for the thing I’m trying to do, it would be nice to know, vs. I just still don’t really understand the syntax of what needs to go where.

1 Like

A command is not ’ run’ within a shell step, instead it is used as a step.

       - downstream 
       - run: my tests

‘run:’ causes a shell to be created on the target executor, so bash on most Linux based environments, so the example code above will run the command you have defined, but then error out on your use of run:
The correct formatting would be something like

           - downstream 
           - run: 
               name: Some text title that will be used in the output log
               command: |
                        touch file
                        rm file

I think you have been tripped up by the fact that ‘commands:’ is used to define new YAML level commands (think a procedure or function for most languages), while ‘command:’ is used to express the shell script to be used by the ‘run’ command.

< edited a number of times to try and make things seem clearer >

thanks! It’s confusing when the ‘validator’ tells me my syntax is ‘valid’, but based on what you’re saying, it’s clearly not.

It’s a valid CircleCI config in the sense that it will try to run downstream as a shell command in the pipeline – the config validator has no way to know whether the actual things run inside a shell command are valid.

Yeah, I get that, I do understand how programming works. I’m just saying I think the validator could be a little more sophisticated in what it’s checking.