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.