Circle CI Unable to Find ANT Build.xml Targets

Hello,

I am new to Circle CI, in my assigned project there are already implemented Circle CI workflows which utilizes Context’s Environment Variables to pass dynamic Values to ANT Script which finally does the Deployment related activities.

The project has an ANT Target which is working correctly and all the workflows are executing well. The command in a step of config.yml is

ant -lib lib/ -Denvdataroot=$envdataroot -Demail_service_token=$email_service_token -Dselective=$selective -DreleaseName=$releaseName -DCIRCLECI_PIPELINE_GIT_REVISION=$CIRCLECI_PIPELINE_GIT_REVISION -DCIRCLECI_PIPELINE_GIT_BASE_REVISION=$CIRCLECI_PIPELINE_GIT_BASE_REVISION deploymentWithCircleci -buildfile build.xml

I need to enhance this command with an extra set of dynamic variable which I get from Contexts. The new command would look like this -

ant -lib lib/ -Denvdataroot=$envdataroot -Dnewservice_email=$newservice_email -Demail_service_token=$email_service_token -Dselective=$selective -DreleaseName=$releaseName -DCIRCLECI_PIPELINE_GIT_REVISION=$CIRCLECI_PIPELINE_GIT_REVISION -DCIRCLECI_PIPELINE_GIT_BASE_REVISION=$CIRCLECI_PIPELINE_GIT_BASE_REVISION deploymentWithCircleci -buildfile build.xml

But the new command fails throwing an exception BUILD FAILED
Target "****************************" does not exist in the project “Project_Name”.

I debugged by listing down the available targets in the build.xml and the deploymentWithCircleci is available.

Is this a Circle CI bug? I tried providing a hard coded value, like -Dnewservice_email=serviceemail.dummy@gmail.com and this worked correctly with the enhanced command, but it fails when I add a dynamic variable to the Target Command.

Please help, I am not sure what actually is causing it? Is there a step that I am missing here?

Thanks in advance,
Sankalp

Hi @meta-sankalp-vyas,

From your explanation, i understand that you wanted to pass a new option -Dnewservice_email=$newservice_email

- ant -lib lib/ -Denvdataroot=$envdataroot -Demail_service_token=$email_service_token -Dselective=$selective -DreleaseName=$releaseName -DCIRCLECI_PIPELINE_GIT_REVISION=$CIRCLECI_PIPELINE_GIT_REVISION -DCIRCLECI_PIPELINE_GIT_BASE_REVISION=$CIRCLECI_PIPELINE_GIT_BASE_REVISION deploymentWithCircleci -buildfile build.xml
+ ant -lib lib/ -Denvdataroot=$envdataroot -Dnewservice_email=$newservice_email -Demail_service_token=$email_service_token -Dselective=$selective -DreleaseName=$releaseName -DCIRCLECI_PIPELINE_GIT_REVISION=$CIRCLECI_PIPELINE_GIT_REVISION -DCIRCLECI_PIPELINE_GIT_BASE_REVISION=$CIRCLECI_PIPELINE_GIT_BASE_REVISION deploymentWithCircleci -buildfile build.xml

I would like to confirm if you are trying to pass a dynamic environment variable (env var) from one step into the next step?

Perhaps, you can share a snippet of your .circleci/config.yml (just the relevant parts will do)?

Thank you!

Yes @kelvintaywl, I am trying to pass the environment variable from Contexts to the build.xml target.

A code snippet of build flow is below. The step “Get Changes For Deploy” is failing. Everything else is working fine.

build:
    machine: true
    working_directory: ~/ci_app
    environment:
      - DX_CLI_URL: https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
      - TESTLEVEL: RunSpecifiedTests
      - TESTCLASSLIST: <TESTCLASSLIST>
      - CIRCLE_COMPARE_URL: << pipeline.project.git_url >>/compare/<< pipeline.git.base_revision >>..<<pipeline.git.revision>>
      - CIRCLECI_PIPELINE_GIT_REVISION: <<pipeline.git.revision>>
      - CIRCLECI_PIPELINE_GIT_BASE_REVISION: << pipeline.git.base_revision >>
	  - selective: #yesPlease
      - releaseName: #2020.10.30
      
    steps:
      - checkout # check out the code in the project directory
      - run:
          name: The First Step
          command: |
            echo 'Hello Developer!'
            echo 'This is the delivery pipeline'
      - run:
          name: Download CLI
          command: |
            mkdir sfdx
            wget -qO- $DX_CLI_URL | tar xJ -C sfdx --strip-components 1
      - run:
          name: Install CLI
          command: |
            ./sfdx/install
            sfdx
            mkdir tmp
      - run:
          name: Set HEAD in GitHub Repo
          command: |
            #Use a Git pull command to set HEAD correctly in Repo. For build.xml to work properly 
            #below git pull command actually is git pull origin BRANCH NAME from where build is to happen i.e. master/develop/feature etc.
            git config user.email "<git-useremail>"
            git config user.name "<git-username>"
            #git pull origin develop
            git pull origin << pipeline.git.branch >>
      - run:
          name: Get Changes For Deploy
          command: |
            #Using Ant script copy only changed files(and related metadata files) to a deployment source directory 
            #ant -lib lib/ -buildfile build.xml
            ant -lib lib/ -Denvdataroot=$envdataroot -Dnewservice_email=$newservice_email -Demail_service_token=$email_service_token -Dselective=$selective -DreleaseName=$releaseName -DCIRCLECI_PIPELINE_GIT_REVISION=$CIRCLECI_PIPELINE_GIT_REVISION -DCIRCLECI_PIPELINE_GIT_BASE_REVISION=$CIRCLECI_PIPELINE_GIT_BASE_REVISION deploymentWithCircleci -buildfile build.xml
      - run:
          name: Decrypt server key
          command: |
            #Decrypt server key
			
      - run:
         name: Authorize Target Deployment Org
         command: |
           #Authorize target Deployment org
           
      - run:
          name: convert the files in deploy folder to MDAPI format
          command: |
            #from SFDX project structure CONVERT TO MDAPI format and deploy

hey @meta-sankalp-vyas ,

thanks for sharing a snippet of your CircleCI config.

Can you confirm if you’ve passed the context into the build job itself?
For CircleCI to inject the environment variables via contexts, you would need to include the context in the job within the workflow declaration.
You can find more details on CircleCI documentation regarding contexts here.

Here is an example assuming your project has a context named my-secret-vault

# .circleci/config.yml
version: 2.1

jobs:
  build:
    machine: true
    working_directory: ~/ci_app
    steps:
      # this should be passed from the context
      - run: echo "env var newservice_email = ${newservice_email}"

workflows:
  version: 2
  my_workflow:
    jobs:
      - build:
          context:
            - my-secret-vault

Hey @kelvintaywl,

Yes I confirm that the context is specified in the workflow.

workflows:
  version: 2
  deploy-feature:
    jobs:
      - build:
          name: deploy-feature
          context: Context-Build
          filters:
            branches:
              only: /^feature\/.*/

I have checked the environment variable as well, it is also present in the Context specified. I have debugged and echoed the Environment Variable and it prints ********************* while running the CIRCLE CI workflow.

@meta-sankalp-vyas

I see! Thank you for sharing :slight_smile:

I have debugged and echoed the Environment Variable and it prints ********************* while running the CIRCLE CI workflow.

Does that mean your issue is now resolved?

No @kelvintaywl , the debug statement was just to verify if the variable is available just before calling the build.xml command, but when passing that variable to command, it still throws exception.

We made a workaround in the project to don’t use the variable for now, so things are working but this is not resolved.

Thanks for the help though, Please let me know if you come across any solution for this in the future.

Sankalp.