@@ -12,6 +12,7 @@ import { ALIYUN_CLI, ALIYUN_CONFIG_FILE } from '../../constant';
1212import Acc from '@serverless-devs/acc/commands/run' ;
1313import fs from 'fs-extra' ;
1414import getAccountId from '../getAccountId' ;
15+ import { isCiCdEnvironment } from '@serverless-devs/utils' ;
1516
1617const Crypto = require ( 'crypto-js' ) ;
1718
@@ -46,6 +47,10 @@ async function getCredential(...args: any[]) {
4647 if ( access === ALIYUN_CLI ) {
4748 result = await getAcc ( ) ;
4849 } else {
50+ const aliasFromEnv = process . env . serverless_devs_access_cicd_alias_name ;
51+ if ( isCiCdEnvironment ( ) && aliasFromEnv ) {
52+ access = aliasFromEnv ;
53+ }
4954 result = await getCredentialWithAccess ( access , ...params ) ;
5055 }
5156
@@ -127,6 +132,10 @@ async function getCredentialWithAccess(access?: string, ...args: any[]) {
127132 logger . debug ( `access information: ${ JSON . stringify ( result , null , 2 ) } ` ) ;
128133 return trim ( result ) ;
129134 }
135+ if ( isCiCdEnvironment ( ) ) {
136+ // cicd 环境未获取到密钥信息,抛出异常
137+ throw new Error ( `The access ${ accessAlias } is not found.` ) ;
138+ }
130139
131140 const userInfo = await getYamlContent ( path . join ( getRootHome ( ) , 'access.yaml' ) ) ;
132141
@@ -161,8 +170,7 @@ async function getCredentialWithAccess(access?: string, ...args: any[]) {
161170 }
162171 const result = formatValue ( userInfo , selectAccess ) ;
163172 logger . warn (
164- `\n\n${
165- os . platform ( ) == 'win32' ? '' : '🤡'
173+ `\n\n${ os . platform ( ) == 'win32' ? '' : '🤡'
166174 } If you don't want to select access every time, configure it in yaml:${ chalk . underline . cyan (
167175 'https://github.com/Serverless-Devs/Serverless-Devs/discussions/149' ,
168176 ) } \n\n`,
0 commit comments