groovy - 无法使用 CredentialInterceptor 测试 BaselinePipelineTest
问题描述
我正在尝试在我的 Jenkins 脚本管道中测试一个函数。
void doSomeDockerThings(){
withCredentials([[$class: 'UsernamePasswordMultiBinding', creditialsId: 'my_creds', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh "docker login -u $USERNAME -p '$PASSWORD' $DTR"
}
}
从扩展 BasePipelineTest 的 Groovy 单元测试中,我有以下测试方法。
@Test
void testDoSomeDockerThings(){
helper.registerAllowedMethod( "withCredentials", [LinkedHasMap.class, Closure.class], null );
helper.registerAllowedMethod( "sh", [String.class], {c -> return c; })
binding.setVariable( "USERNAME", "user" );
binding.setVariable( "PASSWORD", "password" );
binding.setVariable( "DTR", "Docker_Trusted_Registry" );
}
我现在要做的是编写一个断言,该命令按照我的预期执行。既然那是在 withCredentials 的 Closer 中,我该如何验证呢?
sh "docker login -u $USERNAME -p '$PASSWORD' $DTR"
我也尝试过使用 withCredentialsInterceptor ,但我似乎无法获得符合预期的语法。如果有人有这样的例子,我将不胜感激。
helper.registerAllowedMethod( "withCredentials", [LinkedHasMap.class, Closure.class], withCredentialsInterceptor );
我真的很难找到文档或示例是如何做到这一点的。
解决方案
推荐阅读
- java - 我需要在字符串数组中打印所有唯一单词但不确定如何
- c# - '有效载荷数据类型 MSG_TYPE 的集合类型不存在。'
- php - Jquery + Ajax 不能正常工作,为什么?
- r - R闪亮的应用程序错误:gsub函数中用于花括号的意外字符串常量
- python - Google REST API 支持团队驱动器无法正常工作
- python - Python-STL 文件缩减
- postgresql - PostgreSQL 是否正确了解夏令时?
- windows - 如何使用 AutiIt 模拟使用 AutoIt for IME 而非英语的击键
- python - 在适当的二叉树中将内部节点与外部节点相关联
- c# - ASP.NET Web API 在通过 xamarin 移动应用程序访问时返回内部服务器 500 错误。?