I am having a maven project previously built using bitbucket pipeline. I want to migrate it to circleCI. My config file looks like as follow
version: 2.1
orbs:
docker: circleci/docker@2.2.0 # Replace x.y.z with the latest version of the Docker orb
jobs:
build:
docker:
- image: maven:3.9.0-eclipse-temurin-17-focal
steps:
- checkout
# You can customize this section according to your Maven build steps
- run:
name: Build
command: mvn clean install -s settings.xml
# No need to manually build the Docker image, use the existing Dockerfile
- setup_remote_docker:
version: 20.10.7
# Use the following command to build and tag the Docker image
- run:
name: Build Docker Image
command: |
docker info
docker build -t nexus:latest .
docker tag nexus:latest kuldeepiitg/nexus:latest
docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN
docker push kuldeepiitg/nexus:latest
workflows:
version: 2
build-and-deploy:
jobs:
- build
But it is failing with following error.
#!/bin/bash -eo pipefail
docker info
docker build -t nexus:latest .
docker tag nexus:latest kuldeepiitg/nexus:latest
docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN
docker push kuldeepiitg/nexus:latest
/bin/bash: docker: command not found
Exited with code exit status 127
What should I change to make it work?
Read the documentation and came up with working elegant solution finally. I am also finding artifactId and version to build docker image.
version: 2.1
orbs:
docker: circleci/docker@2.2.0 # Replace x.y.z with the latest version of the Docker orb
jobs:
build:
docker:
- image: cimg/openjdk:17.0.7
steps:
- checkout
# You can customize this section according to your Maven build steps
- run:
name: Build
command: mvn clean install -s settings.xml
# No need to manually build the Docker image, use the existing Dockerfile
- setup_remote_docker:
version: 20.10.7
docker_layer_caching: true
# Use the following command to build and tag the Docker image
- run:
name: Build Docker Image
command: |
export MVN_ARTIFACT_ID=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' --non-recursive exec:exec)
export MVN_PROJECT_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
export IMAGE_NAME=kuldeepiitg/$MVN_ARTIFACT_ID:$MVN_PROJECT_VERSION
echo "Building image ============== $IMAGE_NAME ==============="
docker build -t $IMAGE_NAME --build-arg MVN_PROJECT_VERSION=$MVN_PROJECT_VERSION .
docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN
docker push $IMAGE_NAME
workflows:
version: 2
build-and-deploy:
jobs:
- build