strange behavior with withCredential command in pipeline

17 views
Skip to first unread message

Shurik Gefter

unread,
Jan 21, 2021, 2:12:40 AM1/21/21
to jenkin...@googlegroups.com
Hi,

I have very strange behavior with withCredential command in Jenkins.

I'm trying to find the reason for it already for a few days without success.

I have a shared library that parses some yaml file and after it calls my method that downloads the helm chart from nexus.

The method look like

def getHelmChartFileName(helmChartNexusUrl, nexusRepoCred, version, repoName, chartName, stepName) {
        def additionalCommandParameters = ''
        withCredentials([usernamePassword(credentialsId:nexusRepoCred, passwordVariable:'helmPassword',
                                                usernameVariable:'helmUsername')]) {
            additionalCommandParameters = " --username ${helmUsername} --password ${helmPassword}"
        }
        def helmRepoName = '__' + chartName + '__'
        def status = sh (script:"""
                        set +xe
                        helm repo add ${helmRepoName} ${helmChartNexusUrl} ${additionalCommandParameters}
                    """,
                    returnStdout:true).trim()
        if (!status.contains('has been added to your repositories')) {
            print("${stepName} Failed to run command: helm repo add ${helmRepoName} ${helmChartNexusUrl} ${additionalCommandParameters}")
            throw new Exception("${stepName} Failed to run command: helm repo add ${helmRepoName} ${helmChartNexusUrl} ${additionalCommandParameters}")
        }
        print("${stepName} helm repo [${helmChartNexusUrl}] added successfully")
}

When it run part of pipeline I recognize that it take ~ 5-6 sec to pass the withCredential command to the first command in sh (set +xe )

In the console output I see
[Pipeline] withCredentials
20:34:03  Masking supported pattern matches of $helmUsername or $helmPassword
[Pipeline] {
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] sh
20:34:08  + set +xe

When I create a separate method that does only this section and run it in a different pipeline on the same nexus, the interval is less than 1sec.

Maybe can you light me what can be the reason for this delay?

--
Thanks,

Shurik
Reply all
Reply to author
Forward
0 new messages