如何获得Jenkins全局配置中定义的密码?
默认情况下,密码不会注入,我正在尝试下面的代码,并且能够访问“全局属性”,但不能使用密码。
def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars()
println envVars['MY_VARIABLE']
答案 0 :(得分:1)
答案 1 :(得分:1)
您是指Jenkins-> Manage Jenkins->全局属性吗?
如果是,下面是我们如何在常规脚本中检索它们:
import jenkins.model.*
instance = Jenkins.getInstance()
globalNodeProperties = instance.getGlobalNodeProperties()
globalNodeProperties.each {
envVars = it.getEnvVars()
if (envVars.get('ARTIFACTORY_USR') != null) {
artifactory_usr = envVars.get('ARTIFACTORY_USR');
}
if (envVars.get('ARTIFACTORY_PSW') != null) {
artifactory_pwd = envVars.get('ARTIFACTORY_PSW');
}
}
ARTIFACTORY_USR和ARTIFACTORY_PSW是预定义的全局属性
答案 2 :(得分:0)
通常,我在Jenkins->凭证页面中创建凭证以访问管道中的凭证。
如何在詹金斯中创建凭证 1.打开凭据页面(詹金斯->凭据) 2.使用用户名和密码创建一个凭证,并定义一个有效的ID(例如:myCredentialId)
如何在管道中使用withCredentials访问凭据
class Pair {
public:
int *pa,*pb;
Pair(int, int);
Pair(const Pair &);
~Pair();
};
/*
* Implement its member functions below.
*/
Pair::Pair(int a, int b){
pa = new int;
pb = new int;
*pa = a;
*pb = b;
}
Pair::Pair(const Pair & other){
pa = new int;
pb = new int;
*pa = *(other.pa);
*pb = *(other.pb);
}
Pair::~Pair(){
delete pa;
delete pb;
}
/* Here is a main() function you can use
* to check your implementation of the
* class Pair member functions.
*/
int main() {
Pair p(15,16);
Pair q(p);
Pair *hp = new Pair(23,42);
delete hp;
std::cout << "If this message is printed,"
<< " at least the program hasn't crashed yet!\n"
<< "But you may want to print other diagnostic messages too." << std::endl;
return 0;
}
}