@@ -393,37 +393,42 @@ function maskSecrets(str) {
393393 . replace ( / - - a c c e s s - t o k e n = ' .* ?' / g, '--access-token=***' ) ;
394394}
395395
396- async function configureJfrogCliServer ( jfrogService , serverId , cliPath , buildDir ) {
397- let oidcProviderName = tl . getEndpointAuthorizationParameter ( jfrogService , 'oidcProviderName' , true ) ;
398- let oidcAccessToken ;
399-
400- if ( oidcProviderName ) {
401- let serviceUrl = tl . getEndpointUrl ( jfrogService , false ) ;
402- let platformUrl = '' ;
403- try {
404- platformUrl = tl . getEndpointAuthorizationParameter ( jfrogService , 'jfrogPlatformUrl' , true ) ;
405- } catch ( error ) {
406- console . warn ( 'Failed to get platform url from field: ' + error + '\nparsing from url instead' ) ;
407- }
408- if ( ! platformUrl || ! platformUrl . trim ( ) ) {
409- platformUrl = parsePlatformUrlFromServiceUrl ( serviceUrl ) ;
410- }
411- oidcAccessToken = await exchangeOidcTokenAndSetStepVariables ( jfrogService , platformUrl , oidcProviderName , cliPath , buildDir ) ;
396+ async function fetchOidcTokenIfConfigured ( service , cliPath , buildDir ) {
397+ const oidcProviderName = tl . getEndpointAuthorizationParameter ( service , 'oidcProviderName' , true ) ;
398+ if ( ! oidcProviderName ) {
399+ return undefined ;
412400 }
401+ const serviceUrl = tl . getEndpointUrl ( service , false ) ;
402+ let platformUrl = '' ;
403+ try {
404+ platformUrl = tl . getEndpointAuthorizationParameter ( service , 'jfrogPlatformUrl' , true ) ;
405+ } catch ( error ) {
406+ console . warn ( 'Failed to get platform url from field: ' + error + '\nparsing from url instead' ) ;
407+ }
408+ if ( ! platformUrl || ! platformUrl . trim ( ) ) {
409+ platformUrl = parsePlatformUrlFromServiceUrl ( serviceUrl ) ;
410+ }
411+ return exchangeOidcTokenAndSetStepVariables ( service , platformUrl , oidcProviderName , cliPath , buildDir ) ;
412+ }
413413
414+ async function configureJfrogCliServer ( jfrogService , serverId , cliPath , buildDir ) {
415+ const oidcAccessToken = await fetchOidcTokenIfConfigured ( jfrogService , cliPath , buildDir ) ;
414416 return configureSpecificCliServer ( jfrogService , '--url' , serverId , cliPath , buildDir , oidcAccessToken ) ;
415417}
416418
417- function configureArtifactoryCliServer ( artifactoryService , serverId , cliPath , buildDir ) {
418- return configureSpecificCliServer ( artifactoryService , '--artifactory-url' , serverId , cliPath , buildDir ) ;
419+ async function configureArtifactoryCliServer ( artifactoryService , serverId , cliPath , buildDir ) {
420+ const oidcAccessToken = await fetchOidcTokenIfConfigured ( artifactoryService , cliPath , buildDir ) ;
421+ return configureSpecificCliServer ( artifactoryService , '--artifactory-url' , serverId , cliPath , buildDir , oidcAccessToken ) ;
419422}
420423
421- function configureDistributionCliServer ( distributionService , serverId , cliPath , buildDir ) {
422- return configureSpecificCliServer ( distributionService , '--distribution-url' , serverId , cliPath , buildDir ) ;
424+ async function configureDistributionCliServer ( distributionService , serverId , cliPath , buildDir ) {
425+ const oidcAccessToken = await fetchOidcTokenIfConfigured ( distributionService , cliPath , buildDir ) ;
426+ return configureSpecificCliServer ( distributionService , '--distribution-url' , serverId , cliPath , buildDir , oidcAccessToken ) ;
423427}
424428
425- function configureXrayCliServer ( xrayService , serverId , cliPath , buildDir ) {
426- return configureSpecificCliServer ( xrayService , '--xray-url' , serverId , cliPath , buildDir ) ;
429+ async function configureXrayCliServer ( xrayService , serverId , cliPath , buildDir ) {
430+ const oidcAccessToken = await fetchOidcTokenIfConfigured ( xrayService , cliPath , buildDir ) ;
431+ return configureSpecificCliServer ( xrayService , '--xray-url' , serverId , cliPath , buildDir , oidcAccessToken ) ;
427432}
428433
429434/**
@@ -738,10 +743,10 @@ async function configureDefaultJfrogServer(serverId, cliPath, workDir) {
738743 * @param cliPath - Path to JFrog CLI executable.
739744 * @param workDir - Working directory.
740745 */
741- function configureDefaultArtifactoryServer ( usageType , cliPath , workDir ) {
746+ async function configureDefaultArtifactoryServer ( usageType , cliPath , workDir ) {
742747 let artifactoryService = tl . getInput ( 'artifactoryConnection' , true ) ;
743748 const serverId = assembleUniqueServerId ( usageType ) ;
744- configureArtifactoryCliServer ( artifactoryService , serverId , cliPath , workDir ) ;
749+ await configureArtifactoryCliServer ( artifactoryService , serverId , cliPath , workDir ) ;
745750 useCliServer ( serverId , cliPath , workDir ) ;
746751 return serverId ;
747752}
@@ -752,10 +757,10 @@ function configureDefaultArtifactoryServer(usageType, cliPath, workDir) {
752757 * @param cliPath - Path to JFrog CLI executable.
753758 * @param workDir - Working directory.
754759 */
755- function configureDefaultDistributionServer ( usageType , cliPath , workDir ) {
760+ async function configureDefaultDistributionServer ( usageType , cliPath , workDir ) {
756761 let distributionService = tl . getInput ( 'distributionConnection' , true ) ;
757762 const serverId = assembleUniqueServerId ( usageType ) ;
758- configureDistributionCliServer ( distributionService , serverId , cliPath , workDir ) ;
763+ await configureDistributionCliServer ( distributionService , serverId , cliPath , workDir ) ;
759764 useCliServer ( serverId , cliPath , workDir ) ;
760765 return serverId ;
761766}
@@ -766,10 +771,10 @@ function configureDefaultDistributionServer(usageType, cliPath, workDir) {
766771 * @param cliPath - Path to JFrog CLI executable.
767772 * @param workDir - Working directory.
768773 */
769- function configureDefaultXrayServer ( usageType , cliPath , workDir ) {
774+ async function configureDefaultXrayServer ( usageType , cliPath , workDir ) {
770775 let xrayService = tl . getInput ( 'xrayConnection' , true ) ;
771776 const serverId = assembleUniqueServerId ( usageType ) ;
772- configureXrayCliServer ( xrayService , serverId , cliPath , workDir ) ;
777+ await configureXrayCliServer ( xrayService , serverId , cliPath , workDir ) ;
773778 useCliServer ( serverId , cliPath , workDir ) ;
774779 return serverId ;
775780}
@@ -1265,14 +1270,14 @@ function assembleUniqueServerId(usageType) {
12651270 * @param repoDeploy - Repository to use for deploying. Pass a falsy value to skip.
12661271 * @returns {string[] }
12671272 */
1268- function createBuildToolConfigFile ( cliPath , cmd , requiredWorkDir , configCommand , repoResolver , repoDeploy ) {
1273+ async function createBuildToolConfigFile ( cliPath , cmd , requiredWorkDir , configCommand , repoResolver , repoDeploy ) {
12691274 let cliCommand = cliJoin ( cliPath , configCommand ) ;
12701275 let serverIdResolve ;
12711276 let serverIdDeploy ;
12721277 if ( repoResolver ) {
12731278 // Configure Artifactory resolver server.
12741279 const usageType = cmd + tl . getInput ( 'command' , true ) + '_resolver' ;
1275- serverIdResolve = configureDefaultArtifactoryServer ( usageType , cliPath , requiredWorkDir ) ;
1280+ serverIdResolve = await configureDefaultArtifactoryServer ( usageType , cliPath , requiredWorkDir ) ;
12761281
12771282 // Add serverId and repo to config command.
12781283 cliCommand = cliJoin ( cliCommand , '--server-id-resolve=' + quote ( serverIdResolve ) ) ;
@@ -1281,7 +1286,7 @@ function createBuildToolConfigFile(cliPath, cmd, requiredWorkDir, configCommand,
12811286 if ( repoDeploy ) {
12821287 // Configure Artifactory deployer server.
12831288 const usageType = cmd + tl . getInput ( 'command' , true ) + '_deployer' ;
1284- serverIdDeploy = configureDefaultArtifactoryServer ( usageType , cliPath , requiredWorkDir ) ;
1289+ serverIdDeploy = await configureDefaultArtifactoryServer ( usageType , cliPath , requiredWorkDir ) ;
12851290
12861291 // Add serverId and repo to config command.
12871292 cliCommand = cliJoin ( cliCommand , '--server-id-deploy=' + quote ( serverIdDeploy ) ) ;
0 commit comments