Troubleshooting Gitlab-ci. yaml

Hello,
one of my gitlab ci jobs are failing and I wanted to know the proper way ‘syntax’ to inject go path into .gitlab-ci.yaml. I am getting unknown * Unknown alias: inject-gopath

  PACKAGE_PATH: /Users/rodneybizzell/go/src/github.com/rbizzell40/gitlab-ci

stages:
  - dep
  - test
  - build

.anchors:
  - &inject-gopath
      mkdir -p $(dirname ${PACKAGE_PATH})
      && ln -s ${CI_PROJECT_DIR} ${PACKAGE_PATH}
      && cd ${PACKAGE_PATH}
dep:
  stage: dep
  image: golang:1.10-alpjine3.7
  before_script:
    - apk add --no-cache curl git
    - curl -sSL https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 -o /go/bin/dep
    - chmod +x /go/bin/dep
    - *inject-gopath
  script:
    - dep ensure -v -vendor-only
  artifacts:
    name: "vendor=$CI_PIPELINE_ID"
    paths:
      - vendor/
    expire_in: 1 hour


test:
  stage:
  dependencies:
    - dep
  image: golang:1.10-alpine3.7
  before_script:
    - *inject-gopath
  script:
    - go test ./...
build:
  stage: build
  dependencies:
    - dep
  image: docker:17
  services:
    - docker:dind
  script:
    - docker build -t app .```

I’m not sure what you want to achieve here.

Could you elaborate?

I was trying to build this docker image with golang. I need to pass package directory where to go code is but it doesn’t like syntax mkdir -p $(dirname ${PACKAGE_PATH}

No, it doesn’t like the syntax of the line before that. & introduces an anchor, but you can not use it like that, so you need to use it correctly or not at all.

Can u point into how to I understand that. That is why I am asking for help. Telling me I am using it wrong isn’t helping me. If u can help me can u try to speak in a more professional manner. You dont have to come off arrogant

Sorry, I didn’t mean to. Writing texts on a mobile is hard.

As in the snippet you have shown us the inject-gopath isn’t used anywhere, it’s probably the easiest to remove that.

But then again .anchors would be a noop then.

So my assumption is, that you actually wanted this:

.anchors: &inject-gopath
  -|
      mkdir -p $(dirname ${PACKAGE_PATH})
      && ln -s ${CI_PROJECT_DIR} ${PACKAGE_PATH}
      && cd ${PACKAGE_PATH}

And then you only have to use that anchor where it is appropriate, perhaps in before scripts like this:

before_script:
  <<: *Inject-gopath

PS: there might still be small details in the syntax I got wrong. I’m still on a mobile and don’t have a yaml reference at hand.

Ok I appreciate your help definitely.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.