Shared workspace error


#1

Hi,

I am following the instructions to use a share workspace described here

Using Workspaces to Share Artifacts Among Jobs

From this section:

defaults: &defaults
working_directory: /tmp
docker:
- image: buildpack-deps:jessie

I get the following error:

Configuration errors: 2 errors occurred:

* error parsing config: yaml: line 2: mapping values are not allowed in this context
* job 'build' is not found

Any reason why is it failing?


#2

Can you link to where you’re seeing it for the full context?


#3

Should I post the build link here? Or just the yml file? Thanks!


#4

The full YAML is sufficient.


#5
defaults: &defaults
  working_directory: ~/workspace
    docker:
      - image: xxx
jobs:
  build:
    <<: *defaults
        environment:          
          TEST_REPORTS: ~/test-reports
          TEST_ARTIFACTS: ~/test-artifacts
          BUILD_ENVIRONMENT: circle

    steps:
      - checkout

      - run:
          name: Artifacts folders setup
          command: |
            mkdir -p $TEST_REPORTS
            mkdir -p $TEST_ARTIFACTS
      
#      - setup_remote_docker

      - run:
          name: Install NodeJS and Chrome
          command: |
            curl -sL https://deb.nodesource.com/setup_6.x | bash -
            sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
            echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
            wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
            apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
            echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
            echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
            apt-get update -qq
            apt-get install -y nodejs 
            apt-get install -y oracle-java8-installer
            apt-get install -y oracle-java8-set-default
            apt-get install -y google-chrome-stable

      - run:
          name: Install dependencies
          command: |
            npm install -g protractor
            npm install --save-dev cucumber@1.3.3
            npm install --save-dev selenium-webdriver
            npm install --save-dev eyes.selenium
            npm install --save-dev protractor-cucumber-framework
            npm install --save-dev chai@3.5.0
            npm install --save-dev chai-as-promised

  unit_test:
    <<: *defaults
        environment:          
          CIRCLE_SHORT_SHA1: $(eval echo $CIRCLE_SHA1 | cut -c -7)
          TEST_REPORTS: ~/test-reports
          TEST_ARTIFACTS: ~/test-artifacts
          RAILS_ENV: test
          RACK_ENV: development

      - run:
          name: Build the docker image
          command: |
            export CIRCLE_SHORT_SHA1=$(eval echo $CIRCLE_SHORT_SHA1)
            docker login -u $DOCKER_USER -p $DOCKER_PASS
            docker build -t xxx:$CIRCLE_BRANCH -t xxxx:$CIRCLE_SHORT_SHA1 .

      - run:
          name: Database setup
          command: |
            docker-compose run xxx bundle exec rake db:create
            docker-compose run xxx bundle exec rake db:migrate
            docker-compose run xxx bundle exec rake db:seed
            docker-compose run xxx bundle exec rake db:seed:automation

      - run:
          name: Run RSpec tests
          command: |
            docker-compose run xxx bundle exec rspec --color -f d
      
      - store_test_results:
          path: $TEST_REPORTS
          
      - store_artifacts:
          path: $TEST_ARTIFACTS

  func_test:
    <<: *defaults
        environment:          
          CIRCLE_SHORT_SHA1: $(eval echo $CIRCLE_SHA1 | cut -c -7)
          TEST_REPORTS: ~/test-reports
          TEST_ARTIFACTS: ~/test-artifacts
          RAILS_ENV: test
          RACK_ENV: development

      - run:
          name: Build the docker image
          command: |
            export CIRCLE_SHORT_SHA1=$(eval echo $CIRCLE_SHORT_SHA1)
            docker login -u $DOCKER_USER -p $DOCKER_PASS
            docker build -t xxx:$CIRCLE_BRANCH -t xxx:$CIRCLE_SHORT_SHA1 .

      - run:
          name: Run webdriver
          command: |
            webdriver-manager update
            webdriver-manager start
          background: true
   
      - run:
          name: Start Admin
          command: |
            rm -Rf postgres/
            AUTOMATION_INSTANCE=true docker-compose up
          background: true

      - run:
          name: Run protractor tests
          command: protractor automation/conf.js --params.environment="local" --cucumberOpts.tags="@local"

  docker_hub:
    <<: *defaults

      - run:
          name: Login and push docker image
          command: |
            docker login -u $DOCKER_USER -p $DOCKER_PASS
            docker push xxx

workflows:
  version: 2
  admin_workflow:
    jobs:
      - build
      - unit_test
#          filters:
#            branches:
#              only: develop
      - func_test
#          filters:
#            branches:
#              only: /release.*/
      - docker_hub

All possible sensitive commands were either removed or replace by xxx


#6

Excellent! I just solved this exact issue for myself about 15 minutes ago.

Move your defaults snippet to the same level as build under jobs and that will work as expected.


#7

Will do! Thanks!


#8

Mmmm I still get the same error, this is the piece of the yml:

jobs:

  defaults: &defaults
    working_directory: /tmp/workspace
      docker:
        - image: xxx

  build:
    <<: *defaults
        environment:
          TEST_REPORTS: ~/test-reports
          TEST_ARTIFACTS: ~/test-artifacts
          BUILD_ENVIRONMENT: circle

Error is in line 4 now, same line


#9

The docker line looks too far indented and the environment line has too many indents.

Here is a working example with a non-real Docker image:

https://circleci.com/gh/ryanwohara/test-2.0/364#config/containers/0


#10

Great, thanks @rohara I got it to work, but the next job is not executing automatically, should I create a different thread for this?


#11

Are you defining the Workflows section?

https://circleci.com/docs/2.0/configuration-reference/#workflows


#12

Yes, I even see the build under the workflow tab on the left. This is my workflow section:

workflows:
  version: 2
  admin_workflow:
    jobs:
      - build
      - unit_test:
          requires:
            - build
#          filters:
#            branches:
#              only: develop
      - func_test:
          requires:
            - build
#          filters:
#            branches:
#              only: /release.*/
      - docker_hub:
          requires:
            - unit_test
            - func_test

#13

Do you have a unit_test job? Can you link me to your builds? You can PM me if you need.


#14

I marked the post solved by your previous answer since this is something different. Sorry my ignorance, but how do I PM you, new in the forums


#15

There is a message option after clicking on my face.


#16

It seems I can’t PM yet, too new to the forums


#17

Can you try now?


#18

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