0
votes

I want to use Jenkins environment variable for credentials as shown in code below, to specify the Salesforce login username and password, and pass the same to build.xml file so that I can deploy the code to Salesforce platform using Ant migration tool. How can this be done?

Jenkinsfile:

environment
            {
                SERVICE_CREDS=credentials('salesforce-creds')

            }


    stages
    {

         stage('Deploy')
         {
            steps
            {
                echo "Deploying"

                bat 'ant -f ./build.xml CIDeploy'
            }   

         }
      }

build.xml:

<project basedir="." xmlns:sf="antlib:com.salesforce">

    <property environment="env"/>


   <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
   <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
   <condition property="sf.deployroot" value=""> <not> <isset property="sf.deployroot"/>  </not> </condition>




<!--##################################################### Deploy #########################################-->

<target name="CIDeploy">
<sf:deploy
username="$SERVICE_CREDS_USR"
password="$SERVICE_CREDS_PSW"
serverurl="https://login.salesforce.com"
deployRoot="src"/>

  </target>
</project>

Error message from Jenkins console even after logging in to login.salesforce.com site:

BUILD FAILED

C:\Program Files (x86)\Jenkins\workspace\abc\build.xml:26: Invalid username, password, security token; or user locked out.

1

1 Answers

0
votes

Ant lets you pass parameters via command line using -D. Check How do I pass an argument to an Ant task? for some inspiration.

Try to read them from your credentials (sorry, been a while since I configured Jenkins) and pass as ant -f ./build.xml [email protected] -Dsf.password=MySuperSecretPass!!!andOptionallySecurityToken etc.