我只能上传现有的詹金斯机密文件,而不能下载现有的机密文件。
如何下载我上传的现有机密文件以确认其内容?
答案 0 :(得分:7)
如果您可以访问Jenkins实例的脚本控制台(例如,通过在浏览器中访问https://jenkins.example.com/script),则可以运行以下脚本:
master = df.groupby(['Customer','Category','Sub-Category','Product',pd.Grouper(key='Date',freq='A')])['Units_Sold'].sum()\
.unstack()
s1 = master.sum(level=[0,1,2]).assign(Product='Total').set_index('Product',append=True)
s2 = master.sum(level=[0,1])
# Wanted to use assign method but because of the hyphen in the column name you can't.
# Also use the Z in front for sorting purposes
s2['Sub-Category'] = 'ZTotal'
s2['Product'] = ''
s2 = s2.set_index(['Sub-Category','Product'], append=True)
s3 = master.sum(level=[0])
s3['Category'] = 'Total'
s3['Sub-Category'] = ''
s3['Product'] = ''
s3 = s3.set_index(['Category','Sub-Category','Product'], append=True)
master_new = pd.concat([master,s1,s2,s3]).sort_index()
master_new
将Date 2016-12-31 2017-12-31 2018-12-31
Customer Category Sub-Category Product
30XWmt1jm0 Group A X Product 1 651.0 341.0 453.0
Product 2 267.0 445.0 117.0
Product 3 186.0 280.0 352.0
Total 1104.0 1066.0 922.0
Y Product 1 426.0 417.0 670.0
Product 2 362.0 210.0 380.0
Product 3 232.0 290.0 430.0
Total 1020.0 917.0 1480.0
Z Product 1 196.0 212.0 703.0
Product 2 277.0 340.0 579.0
Product 3 416.0 392.0 259.0
Total 889.0 944.0 1541.0
ZTotal 3013.0 2927.0 3943.0
Group B X Product 1 356.0 230.0 407.0
Product 2 402.0 370.0 590.0
Product 3 262.0 381.0 377.0
Total 1020.0 981.0 1374.0
Y Product 1 575.0 314.0 643.0
Product 2 557.0 375.0 411.0
Product 3 344.0 246.0 280.0
Total 1476.0 935.0 1334.0
Z Product 1 278.0 152.0 392.0
Product 2 149.0 596.0 303.0
Product 3 234.0 505.0 521.0
Total 661.0 1253.0 1216.0
ZTotal 3157.0 3169.0 3924.0
Total 6170.0 6096.0 7867.0
3U2anYOD6o Group A X Product 1 214.0 443.0 195.0
Product 2 170.0 220.0 423.0
Product 3 111.0 469.0 369.0
... ... ... ...
somc22Y2Hi Group B Z Total 906.0 1063.0 680.0
ZTotal 3070.0 3751.0 2736.0
Total 6435.0 7187.0 6474.0
zRZq6MSKuS Group A X Product 1 421.0 182.0 387.0
Product 2 359.0 287.0 331.0
Product 3 232.0 394.0 279.0
Total 1012.0 863.0 997.0
Y Product 1 245.0 366.0 111.0
Product 2 377.0 148.0 239.0
Product 3 372.0 219.0 310.0
Total 994.0 733.0 660.0
Z Product 1 280.0 363.0 354.0
Product 2 384.0 604.0 178.0
Product 3 219.0 462.0 366.0
Total 883.0 1429.0 898.0
ZTotal 2889.0 3025.0 2555.0
Group B X Product 1 466.0 413.0 187.0
Product 2 502.0 370.0 368.0
Product 3 745.0 480.0 318.0
Total 1713.0 1263.0 873.0
Y Product 1 218.0 226.0 385.0
Product 2 123.0 382.0 570.0
Product 3 173.0 572.0 327.0
Total 514.0 1180.0 1282.0
Z Product 1 480.0 317.0 604.0
Product 2 256.0 215.0 572.0
Product 3 463.0 50.0 349.0
Total 1199.0 582.0 1525.0
ZTotal 3426.0 3025.0 3680.0
Total 6315.0 6050.0 6235.0
[675 rows x 3 columns]
更改为您要打印的文件名。
此脚本将打印出Jenkins凭证存储区的全局域中文件名为import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.domains.Domain;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
println "Jenkins credentials config file location=" + SystemCredentialsProvider.getConfigFile();
println ""
def fileName = "my-secret-file.txt"
SystemCredentialsProvider.getInstance().getCredentials().stream().
filter { cred -> cred instanceof FileCredentialsImpl }.
map { fileCred -> (FileCredentialsImpl) fileCred }.
filter { fileCred -> fileName.equals( fileCred.getFileName() ) }.
forEach { fileCred ->
String s = new String( fileCred.getSecretBytes().getPlainData() )
println "XXXXXX BEGIN a secret file with fileName=" + fileName + " XXXXXXXXXXXX"
println s
println "XXXXXX END a secret file with fileName=" + fileName + " XXXXXXXXXXXX"
println ""
}
的文件内容。
此脚本的可修复警告:
答案 1 :(得分:2)
如果您具有运行Jenkins的计算机上的Shell访问权限和 sudo / root
/ Jenkins Unix用户权限,则可以通过执行以下操作来检索机密文件以下:
MY_SECRET_FILE_TXT
。在 Command 文本区域中,添加以下Shell脚本:
echo "executing user is $(whoami)"
# remove my-secret-file.txt before possibly getting an overwriting error
rm -f $WORKSPACE/my-secret-file.txt
echo "Jenkins project workspace: $WORKSPACE"
cp $MY_SECRET_FILE_TXT $WORKSPACE
下次为此项目触发构建时,秘密文件应出现在该项目的工作空间中,即位置$WORKSPACE/my-secret-file.txt
。例如,在安装了软件包和守护程序的{em> Ubuntu 14.04.5 LTS 安装中,jenkins
的位置是/var/lib/jenkins/workspace/$JENKINS_PROJECT_NAME/my-secret-file.txt
答案 2 :(得分:0)
脚本控制台标记的答案很好。
此脚本还列出了可以从控制台运行的所有机密: https://github.com/tkrzeminski/jenkins-groovy-scripts/blob/master/show-all-credentials.groovy
答案 3 :(得分:0)