Maven Build Artefact not found in Deploy workflow

I’m trying to migrate my Springboot deployment from 1.0 to 2.0 but for some reason the Deploy Job is not finding the built war file.

I have tested the Build and can see the Artefact but when the Deploy Job starts, it is no longer there.

Post Build ls

Container 0

  • home/
    • circleci/
      • passedon/
        • target/
          • classes/
          • maven-archiver/
          • maven-status/
          • passedon/
          • [passedon.war]
          • [passedon.war.original]

The Build Job

version: 2
jobs:

# The build job
build:
    working_directory: ~/passedon
    machine: true
    steps:

        # Checkout the code from the branch into the working_directory
        - checkout

        # Log the current branch
        - run:
            name: Retrieve GIT Information
            command: |
                echo ${CIRCLE_BRANCH}
                echo ""
                # GET GIT LATEST COMMIT COMMENT TO SET AS APP VERSION FOR BEANSTALK
                COMMIT_MESSAGE=$(git log -1 --pretty=%f)
                export COMMIT_MESSAGE
                echo $COMMIT_MESSAGE

        # Copy Environment specific application.properties and constant file
        - run:
            name: App Properties and Constant file
            command: |
                if [ "${CIRCLE_BRANCH}" == "integration" ]; then
                    echo ""
                    echo "Move Integration Application.Prop File"
                    mv src/main/resources/application.properties.integration src/main/resources/application.properties
                    if [ $? != 0 ]; then
                       echo "FAILED: Move app.prop: $? - Unsuccessful"
                    else
                       echo "SUCCESS: Move app.prop DONE  1 of 2"
                    fi
                    echo ""
                    echo "Move Constant.java File"
                    mv Constant-integration.java src/main/java/com/passedon/Constant.java
                    if [ $? != 0 ]; then
                       echo "FAILED: Move constant: $? - Unsuccessful"
                    else
                       echo "SUCCESS: Constant mv done 2 of 2"
                    fi
                    echo ""
                    echo "MESSAGE: Ensure 2 of 2 Successes"
                    echo ""
                elif [ "${CIRCLE_BRANCH}" == "master" ]; then
                    echo ""
                    echo "Move PRODUCTION Application.Prop File"
                    mv src/main/resources/application.properties.production src/main/resources/application.properties
                    if [ $? != 0 ]; then
                       echo "FAILED: Move app.prop: $? - Unsuccessful"
                    else
                       echo "SUCCESS: Move app.prop DONE  1 of 2"
                    fi
                    echo ""
                    echo "Move Constant.java File"
                    mv Constant-production.java src/main/java/com/passedon/Constant.java
                    if [ $? != 0 ]; then
                       echo "FAILED: Move constant: $? - Unsuccessful"
                    else
                       echo "SUCCESS: Constant mv done 2 of 2"
                    fi
                    echo ""
                    echo "MESSAGE: Ensure 2 of 2 Successes"
                    echo ""
                fi
                echo "Move .ebextensions into the correct folder"
                mv .ebextensions/ src/main/webapp/
                if [ $? != 0 ]; then
                   echo "FAILED: Move ebextension: $? - Unsuccessful"
                else
                   echo "SUCCESS: ebextension mv DONE"
                fi
                echo ""
        - restore_cache: # restore the saved cache after the first run or if `pom.xml` has changed
            key: circleci-demo-java-spring-{{ checksum "pom.xml" }}
        - run: mvn dependency:go-offline # gets the project dependencies
        - save_cache: # saves the project dependencies
              paths:
                - ~/.m2
              key: circleci-demo-java-spring-{{ checksum "pom.xml" }}
        - run:
            name: Build the JAR file
            command: |
              mvn clean package # run the actual tests
              ls -1 ~/passedon/target
        - store_artifacts: # store the uberjar as an artifact
            path: target/passedon.war

# The deploy job
deploy:
    working_directory: ~/passedon
    machine: true
    steps:

       # Log the current branch
        - run:
            name: Show current branch
            command: |
              echo ${CIRCLE_BRANCH}
              ls -l ~/passedon

        # Install AWS cli
        - run:
            name: Install aws cli
            command: |
               sudo apt-get -y -qq update
               sudo apt-get install python-pip python-dev build-essential
               sudo pip install awsebcli --upgrade

        # Deploy to the correct Elastic BEanstalk Environemnt  corresponding to the current branch
        - run:
            name: Deploy to EBS
            command: |
                if [ "${CIRCLE_BRANCH}" == "integration" ]; then
                    echo "START EBS Integration Deployment"
                    eb init --region ap-southeast-2 --platform "64bit Amazon Linux 2017.03 v2.5.1 running Java 8" PassedOn
                    eb use passedon-int-jsb1
                    eb deploy passedon-int-jsb1 --label "$COMMIT_MESSAGE"
                    echo "COMPLETE EBS Integration Deployment done "
                elif [ "${CIRCLE_BRANCH}" == "master" ]; then
                    echo "START EBS PRODUCTION Deployment"
                  # select correct environment and uses the default aws keys setup inside circle ci
                    eb use passedon-prod-jsb
                    # clean the app versions older than 2 days to avoid the 30 versions limit
                    eb labs cleanup-versions --older-than 2 --debug --verbose --force
                    # deploy the war file to beanstalk and set the app version using the latest commit message
                    eb deploy passedon-prod-jsb --label "$COMMIT_MESSAGE"
                    echo "COMPLETE EBS PRODUCTION Deployment done "
                fi

workflows:
    version: 2
    # The build and deploy workflow
    build_and_deploy:
        jobs:
            - build
            # The deploy job will only run on the filtered branches and
            # require the build job to be successful before it starts
            - deploy:
                requires:
                    - build
                filters:
                    branches:
                        only:
                            - integration
                            - master
1 Like

For some reason the copy and paste is not keeping the original formatting. I am also unable to upload the file.

It appears you must have a chr(10) before any comment (#) in the code for it format correctly.

I’ll try formatting using the triple-backtick approach:

# Log the current branch

My text above looks like this:

I'll try formatting using the triple-backtick approach
```
# Log the current branch
```

That doesn’t need a newline. However if I use the indent approach, one is required:

code

My text above is:

That doesn't need a newline. However if I use the indent approach, one _is_ required:

    code

I think the hash thing is a red herring :tropical_fish:

(This message will self-destruct :bomb:).

Aha, yes: jobs always start with a fresh build container, by design. However, you can share things between jobs using a workspace.

I have since attempted using Workspaces which now results in my deploy job with

Error locating workspace root directory: stat /home/circleci/passedon: no such file or directory

My Updated yaml is as follows:

version: 2
jobs:
    # The build job
    build:
        working_directory: ~/passedon
        machine: true
        steps:
            # Checkout the code from the branch into the working_directory
            - checkout
            # Log the current branch
            - run:
                name: Retrieve GIT Information
                command: |
                    echo ${CIRCLE_BRANCH}
                    echo ""
                    # GET GIT LATEST COMMIT COMMENT TO SET AS APP VERSION FOR BEANSTALK
                    COMMIT_MESSAGE=$(git log -1 --pretty=%f)
                    export COMMIT_MESSAGE
                    echo $COMMIT_MESSAGE

            # Copy Environment specific application.properties and constant file
            - run:
                name: App Properties and Constant file
                command: |
                    if [ "${CIRCLE_BRANCH}" == "integration" ]; then
                        echo ""
                        echo "Move Integration Application.Prop File"
                        mv src/main/resources/application.properties.integration src/main/resources/application.properties
                        if [ $? != 0 ]; then
                           echo "FAILED: Move app.prop: $? - Unsuccessful"
                        else
                           echo "SUCCESS: Move app.prop DONE  1 of 2"
                        fi
                        echo ""
                        echo "Move Constant.java File"
                        mv Constant-integration.java src/main/java/com/passedon/Constant.java
                        if [ $? != 0 ]; then
                           echo "FAILED: Move constant: $? - Unsuccessful"
                        else
                           echo "SUCCESS: Constant mv done 2 of 2"
                        fi
                        echo ""
                        echo "MESSAGE: Ensure 2 of 2 Successes"
                        echo ""
                    elif [ "${CIRCLE_BRANCH}" == "master" ]; then
                        echo ""
                        echo "Move PRODUCTION Application.Prop File"
                        mv src/main/resources/application.properties.production src/main/resources/application.properties
                        if [ $? != 0 ]; then
                           echo "FAILED: Move app.prop: $? - Unsuccessful"
                        else
                           echo "SUCCESS: Move app.prop DONE  1 of 2"
                        fi
                        echo ""
                        echo "Move Constant.java File"
                        mv Constant-production.java src/main/java/com/passedon/Constant.java
                        if [ $? != 0 ]; then
                           echo "FAILED: Move constant: $? - Unsuccessful"
                        else
                           echo "SUCCESS: Constant mv done 2 of 2"
                        fi
                        echo ""
                        echo "MESSAGE: Ensure 2 of 2 Successes"
                        echo ""
                    fi
                    echo "Move .ebextensions into the correct folder"
                    mv .ebextensions/ src/main/webapp/
                    if [ $? != 0 ]; then
                       echo "FAILED: Move ebextension: $? - Unsuccessful"
                    else
                       echo "SUCCESS: ebextension mv DONE"
                    fi
                    echo ""

            - restore_cache: # restore the saved cache after the first run or if `pom.xml` has changed
                key: circleci-demo-java-spring-{{ checksum "pom.xml" }}

            - run: mvn dependency:go-offline # gets the project dependencies

            - save_cache: # saves the project dependencies
                  paths:
                    - ~/.m2
                  key: circleci-demo-java-spring-{{ checksum "pom.xml" }}

            - run:
                name: Build the JAR file
                command: |
                  mvn clean package # run the actual tests
                  ls -1 ~/passedon/target

            - persist_to_workspace:
                root: ~/passedon
                paths:
                  - .


    # The deploy job
    deploy:
        working_directory: ~/passedon
        machine: true
        steps:
            - persist_to_workspace:
                root: ~/passedon
                paths:
                  - target
            # Log the current branch
            - run:
                name: Show current branch
                command: |
                  echo ${CIRCLE_BRANCH}
                  ls -l ~/passedon
                  ls -l ~/passedon/target

            # Install AWS cli
            - run:
                name: Install aws cli
                command: |
                   sudo apt-get -y -qq update
                   sudo apt-get install python-pip python-dev build-essential
                   sudo pip install awsebcli --upgrade

            # Deploy to the correct Elastic BEanstalk Environemnt  corresponding to the current branch
            - run:
                name: Deploy to EBS
                command: |
                    if [ "${CIRCLE_BRANCH}" == "integration" ]; then
                        echo "START EBS Integration Deployment"
                        eb init --region ap-southeast-2 --platform "64bit Amazon Linux 2017.03 v2.5.1 running Java 8" PassedOn
                        eb use passedon-int-jsb1
                        eb deploy passedon-int-jsb1 --label "$COMMIT_MESSAGE"
                        echo "COMPLETE EBS Integration Deployment done "
                    elif [ "${CIRCLE_BRANCH}" == "master" ]; then
                        echo "START EBS PRODUCTION Deployment"
                      # select correct environment and uses the default aws keys setup inside circle ci
                        eb use passedon-prod-jsb
                        # clean the app versions older than 2 days to avoid the 30 versions limit
                        eb labs cleanup-versions --older-than 2 --debug --verbose --force
                        # deploy the war file to beanstalk and set the app version using the latest commit message
                        eb deploy passedon-prod-jsb --label "$COMMIT_MESSAGE"
                        echo "COMPLETE EBS PRODUCTION Deployment done "
                    fi

workflows:
    version: 2
    # The build and deploy workflow
    build_and_deploy:
        jobs:
            - build
            # The deploy job will only run on the filtered branches and
            # require the build job to be successful before it starts
            - deploy:
                requires:
                    - build
                filters:
                    branches:
                        only:
                            - integration
                            - master

In your second job, you are trying to persist to workspace when there is nothing to persist. I suspect you want to restore from workspace? I don’t know the exact command, but it will be in the docs.

I could not find any helpful information in the doco in regards to workspaces. The section is about 1 paragraph long and only deals with the workspace.

Hence the request for help.

The command you need is in the configuration example in the link I provided - see the definition of the second job. Make sure you understand what the workspace commands are doing - don’t just copy+paste!

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