0

I'm new to CircleCI. I'm trying to migrating CircleCI1.0 to 2.0 and I got this error:

     #!/bin/bash -eo pipefail
- if [ -n "$(git status --porcelain)" ]; then
        echo "*** Files have been updated. ***";
        git add *;
        git commit -m "latest voter info updates1";
        git push origin master;
        echo "*** Files committed to git. ***";
  else
        echo "*** Files have not changed. Nothing to commit and upload. ***";
  fi

/bin/bash: - : invalid option
Error: Exited with code 1
Step failed
Error: runner failed (exited with 101)
Task failed
Error: task failed

Here is my version 1 config file:

machine:
  timezone:
    America/Los_Angeles
  python:
    version: 2.7.6

compile:
  override:
    - cd tools/scripts && ./compileJSON.py
    - cd ../../
    - if [ -n "$(git status --porcelain)" ]; then 
        echo "*** Files have been updated. ***";
        git add *;
        git commit -m "latest voter info updates";
        git push origin master;
        echo "*** Files committed to git. ***";
      else 
        echo "*** Files have not changed. Nothing to commit and upload. ***";
      fi

deployment:
  production:
    branch: master
    commands:
      - aws s3 cp json s3://foldername/json --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --recursive --include "*.*";

And here is the migrated version of config:

 version: 2
jobs:
  build:
    environment:
      - BASH_ENV: ~/.bashrc
    docker:
      - image: circleci/python:2.7.14
    steps:
      - checkout
      - run:
          name: Build JSon File
          command: cd tools/scripts && ./compileJSON.py
      - run:
          name: Exit Folder
          command: cd ../../
      - run:
             name: install git
             command: sudo apt-get update && sudo apt-get upgrade && sudo apt-get install --no-install-recommends -y git
      - run:
          name: git commit --this command not running
          command: |
                  - if [ -n "$(git status --porcelain)" ]; then
                          echo "*** Files have been updated. ***";
                          git add *;
                          git commit -m "latest user info updates1";
                          git push origin master;
                          echo "*** Files committed to git. ***";
                    else
                          echo "*** Files have not changed. Nothing to commit and upload. ***";
                    fi
workflows:
  version: 2
  build_and_deploy:
    jobs:
      - deploy:
          filters:
            branches:
              only:
                - master

Problem

- run:
              name: git commit --this command not running
              command: |
                      - if [ -n "$(git status --porcelain)" ]; then
                              echo "*** Files have been updated. ***";
                              git add *;
                              git commit -m "latest user info updates1";
                              git push origin master;
                              echo "*** Files committed to git. ***";
                        else
                              echo "*** Files have not changed. Nothing to commit and upload. ***";
                        fi

When above command runs i got the above error. What is wrong with this command? I need local commit if anything changes in repo. How can achieve that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Jagadeesh Govindaraj
  • 6,977
  • 6
  • 32
  • 52

1 Answers1

1

It's what the error is saying. For your new config, in that first if block, you have a dash (-) before if which shouldn't be there.

FelicianoTech
  • 3,894
  • 2
  • 13
  • 18