For come reason I am not able to change my directory when build my pipeline in with Circle CI.
Also the command make is missing in Circle CI :(
file...
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
api:
working_directory: ~/api
docker:
- image: golang:1.19.3-alpine3.16
steps:
- checkout:
path: ~/api
- setup_remote_docker: # (2)
docker_layer_caching: true # (3)
# specify any bash command here prefixed with `run: `
- run: pwd
- run: ls -all
#- run: make mod-vendor
- run: go get -v -t -d ./...
- run: go test -v ./...
- run: go build -o main .
- deploy:
command: |
if [ "${CIRCLE_BRANCH}" == "circle-ci-setup" ]; then
docker build -t ${DOCKER_REPO} .
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} https://index.docker.io/v1/
docker push ${DOCKER_REPO}
fi
client:
working_directory: ~/client
# Specify the execution environment. You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/configuration-reference/#docker-machine-macos-windows-executor
docker:
- image: cimg/node:16.1.0
#- image: nginx:1.21.3-alpine
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout:
path: ~/client
#- restore_cache:
# name: Restore Yarn Package Cache
# keys:
# - yarn-packages-{{ checksum "yarn.lock" }}
- run: pwd
- run: ls -all
- run:
name: Install Dependencies
command: yarn install --immutable
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- .yarn/cache
- .yarn/unplugged
- run:
name: Installing the package.json dependencies
command: yarn
# run build!
#- run: make build-client
- run: yarn build
- persist_to_workspace:
root: .
paths: dist
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
hobby-project-setup:
jobs:
- client
- api
The client part produces an error that reads
yarn run v1.22.10
error Couldn't find a package.json file in "/home/circleci/client"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code exit status 1
CircleCI received exit code 1
and the api
#!/bin/sh -eo pipefail
cd api && go get -v -t -d ./...
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
Exited with code exit status 1
ls-all
#!/bin/sh -eo pipefail
ls -all
total 32
drwxr-xr-x 7 root root 4096 Dec 4 12:12 .
drwx------ 1 root root 33 Dec 4 12:12 ..
drwxr-xr-x 2 root root 24 Dec 4 12:12 .circleci
drwxr-xr-x 4 root root 72 Dec 4 12:12 .git
-rw-r--r-- 1 root root 13 Dec 4 12:12 .gitignore
-rw-r--r-- 1 root root 1369 Dec 4 12:12 Makefile
drwxr-xr-x 6 root root 95 Dec 4 12:12 api
-rw-r--r-- 1 root root 5302 Dec 4 12:12 api.swagger.json
drwxr-xr-x 5 root root 4096 Dec 4 12:12 client
-rw-r--r-- 1 root root 424 Dec 4 12:12 digital-ocean-infra-config.sh
-rw-r--r-- 1 root root 263 Dec 4 12:12 docker-compose.yml
drwxr-xr-x 6 root root 104 Dec 4 12:12 infra
This is the same output for client and api...
and pwd for api
#!/bin/sh -eo pipefail
pwd
/root/api
CircleCI received exit code 0
and pwd for client
#!/bin/bash -eo pipefail
pwd
/home/circleci/client
CircleCI received exit code 0
Doing cd client && yarn or cd api && go build does work but this cannot be the correct way.
How can I set my working directory for each job?
Though there are a few mistakes in your pipeline, your eventual conclusion to
cdinto the subfolder and execute the required command appears to be the correct one from my testing. The current folder cannot be changed the way you want usingworking_directory: ~/api, because thecheckoutstep, that downloads the code, happens after the working directory is set and thecheckout.pathis interpreted as relative to the working directory as per the docs, not as an absolute path like~/api. So with the working directory as~/apiand a checkout step withoutpath, your code will be cloned to~/api. But at that point the folder you want to execute thego buildcommand from would be~/api/api, so you'll still need to runcd apifirst. Similarly if you had used the relative pathapiincheckout.pathwith the working directory as~/api, the code would have been cloned to~/api/api, so now you'd have tocd api/apibefore running the build.These can be illustrated with the outputs from the below test pipeline:
Output of pwd step: (Prints the working directory
/root/test)Output of ls step: (Shows the subfolder
app)Output of cd & ls: (Shows the code cloned inside
/root/test/app)Also the
makecommand not being present is not a CircleCI limitation. When you use adockerexecutor with CircleCI, you are limited to the commands that are present in that docker image. In this case, the imagegolang:1.19.3-alpine3.16does not containmake. I confirmed that by runningdocker run --rm golang:1.19.3-alpine3.16 makefrom my local machine which returned the below error:If a go image with
makeis what you need, CircleCI does provide its own convenience images for go. The CircleCI image for go1.19.3would becimg/go:1.19.3, which does containmake.