我正在尝试访问存储在Jenkins中的AWS凭据,并在Jenkins管道中执行以下操作(Jenkinsfile
)
steps {
withCredentials([usernamePassword(credentialsId: 'eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
sh 'echo $AWS_ACCESS_KEY_ID'
sh 'echo $AWS_SECRET_ACCESS_KEY'
}
}
字符串
它的错误与
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Could not find credentials entry with ID 'eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76'
at org.jenkinsci.plugins.credentialsbinding.MultiBinding.getCredentials(MultiBinding.java:153)
at org.jenkinsci.plugins.credentialsbinding.impl.UsernamePasswordMultiBinding.bind(UsernamePasswordMultiBinding.java:76)
at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution.start(BindingStep.java:114)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:270)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor3000.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:155)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:159)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:129)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
at WorkflowScript.run(WorkflowScript:16)
型
和
withCredentials([[ $class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76', accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh "echo this is ${env.AWS_ACCESS_KEY_ID}"
sh "echo this is ${env.AWS_SECRET_ACCESS_KEY}"
}
型
埃什托
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Could not find credentials entry with ID 'eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76'
at org.jenkinsci.plugins.credentialsbinding.MultiBinding.getCredentials(MultiBinding.java:153)
at com.cloudbees.jenkins.plugins.awscredentials.AmazonWebServicesCredentialsBinding.bind(AmazonWebServicesCredentialsBinding.java:97)
at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution.start(BindingStep.java:114)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:270)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:178)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
at sun.reflect.GeneratedMethodAccessor3000.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:157)
at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
at
型
我确实有证件,ID为eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76
我已安装CloudBees AWS Credentials PluginVersion 1.24
有人知道这里有什么不对吗?
4条答案
按热度按时间ttygqcqt1#
凭证
eb1092d1-0f06-4bf9-93c7-32e5f7b9ef76
不是AWS access key and secret
类型。请在将凭证添加到Jenkins时仔细检查您选择的类型是否正确。您可以通过Jenkins内置工具检查:管道生成器-> SnirkingGenerator如下指南:
1.通过
your jenkins server url/pipeline-syntax/
打开工具,例如https://my.jenkins.com/pipeline-syntax/1.从示例步骤中选择
withCredentials: Bind credentials to variables
1.单击添加按钮,然后从弹出选项中选择
AWS access key and secret
1.从
Credentials
中选择您的凭据,如果您在凭据中找不到任何凭据,则表示您的凭据不是AWS access key and secret
类型1.点击
Generate pipeline script
按钮1.检查生成的脚本中的
credentialsId
是否为eb1092d1-0f06-4bf9-93c7-32e5f7b9e
x1c 0d1x的数据
klr1opcd2#
将上面截图中的代码转换为代码片段,以便于复制
字符串
wooyq4lh3#
您可能需要处理多字段凭据或插件(尚未)支持的供应商特定凭据类型。
在这种情况下,你有几个选择:
1.使用符合您要求的最接近的标准多字段凭据(例如,带密码的身份验证)。
1.使用字符串凭据,将所有字段序列化为secret值(例如,作为JSON或分隔字符串),并在作业脚本中解析它们。(当其他方法不起作用时,这是最后的手段,例如,当secret旋转会导致多个字段更改时。)
示例如下:Jenkins使用主AWS凭据(来自环境)向Secrets Manager进行身份验证。您有一个作业在不同的帐户中执行特定的AWS操作,该帐户使用辅助AWS凭据。您可以选择将辅助AWS凭据编码为JSON,并使用字符串credential foo:
字符串
用户名密码类型凭据的典型示例(此处的示例)如下所示:
型
ReadMore1
ReadMore2的
zsohkypk4#
现在是2023年,AWS凭证根据documentation有一个
withCredentials
绑定:字符串
感兴趣的文档片段:
将一个变量设置为AWS访问密钥,将另一个变量设置为凭据中给定的密钥。
accessKeyVariable
:AWS访问密钥ID的String环境变量名称。如果为空,则使用AWS_ACCESS_KEY_ID
。secretKeyVariable
:String AWS Secret Access Key的环境变量名。如果为空,则使用AWS_SECRET_ACCESS_KEY
。credentialsId
:String要设置为变量的适当类型的凭据。roleArn
:String(可选)roleSessionDurationSeconds
:int(可选)roleSessionName
:String(可选)你也可以在参数输入中使用这些凭证,即使没有文档记录。只要确保
credentialsId
设置为管道参数的名称:型