0

I have a Jenkins script to generate a scratch org, make a user for that scratch org along with a password. When I try to deploy using that username and password I get

build/lib/deploy.xml:26: Invalid username, password, security token; or user locked out.

While running this command

deploy -Dsf.username=test-b1jpm0udc52d@example.com '-Dsf.password=hwmmA0dcpj^yz00D2D000000EJOg!AQwAQBkmxFalTKIXDeFfwAhEBIC3VCeKV8ebz9loGQF1WfjdUrAIEXjFALfDyF2qrI4aVxotSyBh8YgetMrAsQq7yqTxq0gv' -Dsf.namespace=TCADLL -Dsf.developerOrg=f

My assumption is that the token I'm using isn't actually the one needed to deploy, as the one I use for my dev org is much shorter.

The code to generate the scratch org, user, and password are here.

stage('Generate Test Scratch Org') {
            rc = command "${sfdx} force:org:create --targetdevhubusername ${DEV_HUB_USRNM} --definitionfile ${SCRATCH_ORG_DEF} --setalias ${SCRATCH_ORG_ALIAS} --wait 10 --durationdays 1"
            if (rc) {
                error("Unable to create scratch org")
            }
        }
stage('Generate User for Scrach Org') {
            rc = command "${sfdx} force:user:create --setalias ${SCRATCH_USR_ALIAS} --targetusername ${SCRATCH_ORG_ALIAS} --targetdevhubusername ${DEV_HUB_USRNM}"
            if (rc) {
                echo "Wasn't able to make user for scratch org"
                TESTS_FAILED = true
            }
        }
stage('Generate Password for Scrach Org User') {
            rc = command "${sfdx} force:user:password:generate --targetusername ${SCRATCH_ORG_ALIAS}"
            if (rc) {
                echo "Couldn't assign password to user"
                TESTS_FAILED = true
            }
        }
stage('Ant deploy to org') {
            details = sh returnStdout: true, script: "${sfdx} force:user:display --targetusername ${SCRATCH_ORG_ALIAS} --json"
            def jsonSlurper = new JsonSlurperClassic()
            def response = jsonSlurper.parseText(details)
            rc = command "${ant} -f ${BUILD_PATH} deploy -Dsf.username=${response.result.username} -Dsf.password=${response.result.password}${response.result.accessToken} -Dsf.namespace=${NAMEASPACE} -Dsf.developerOrg=f"
            if (rc) {
                echo "Couldn't deploy to org"
                TESTS_FAILED = true
            }
        }

If anyone has any suggestions on something I might've missed, or has a way to access the proper token I'd be thrilled to listen. I'm not using the sfdx:deploy or whatever function because our package isn't an SFDX project so it doesn't like the layout we have.

1 Answer 1

3

I recommend you to use sfdx commands instead of the old ant.

sfdx still will be able to deploy your classic metadata package using a sfdx:mdapi:deploy command.

Use the mdapi commands to retrieve and deploy Metadata API–formatted files that represent components in an org, or to convert Metadata API–formatted metadata into the source format used in Salesforce DX projects.

run sfdx:mdapi:deploy set as target to which metadta should be deployed

1
  • Thanks for the feedback, I'd tried the mdapi once before but ran into a bunch of issues (hence why I was giving ant a go). Since this was providing about as many headaches I took another swing at it and it started working (mostly) so thanks!
    – ConorMoore
    Oct 14, 2021 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.