ChefJenkinsGroovyShellOut: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(syntaxhighlighting for ChefJenkinsGroovyShellOut) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<syntaxhighlight lang | <syntaxhighlight lang=bash> | ||
| | ||
java -jar /opt/jenkins-cli.jar -s http://localhost:8080 help --username admin | java -jar /opt/jenkins-cli.jar -s http://localhost:8080 help --username admin | ||
Line 5: | Line 5: | ||
java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy crypt.groovy --username admin --password-file jenkins_pass.txt | java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy crypt.groovy --username admin --password-file jenkins_pass.txt | ||
========================= | ========================= | ||
</syntaxhighlight> | |||
<syntaxhighlight lang=groovy> | |||
import com.trilead.ssh2.crypto.Base64; | import com.trilead.ssh2.crypto.Base64; | ||
import javax.crypto.Cipher; | import javax.crypto.Cipher; | ||
Line 15: | Line 17: | ||
println(new String(Base64.encode(cipher.doFinal((VALUE_TO_ENCRYPT + MAGIC).getBytes("UTF-8"))))); | println(new String(Base64.encode(cipher.doFinal((VALUE_TO_ENCRYPT + MAGIC).getBytes("UTF-8"))))); | ||
========================= | ========================= | ||
</syntaxhighlight> | |||
<syntaxhighlight lang=ruby> | |||
ruby_block "something" do | ruby_block "something" do | ||
block do | block do | ||
Line 26: | Line 30: | ||
end | end | ||
========================= | ========================= | ||
</syntaxhighlight> | |||
<syntaxhighlight lang=groovy> | |||
UNENC_PW="admin" | UNENC_PW="admin" | ||
cat <<EOF | java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy = | cat <<EOF | java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy = |
Latest revision as of 22:56, 24 January 2018
java -jar /opt/jenkins-cli.jar -s http://localhost:8080 help --username admin
java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy bla.txt --username admin
java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy crypt.groovy --username admin --password-file jenkins_pass.txt
=========================
import com.trilead.ssh2.crypto.Base64;
import javax.crypto.Cipher;
import jenkins.security.CryptoConfidentialKey;
import hudson.util.Secret;
CryptoConfidentialKey KEY = new CryptoConfidentialKey(Secret.class.getName());
Cipher cipher = KEY.encrypt();
String MAGIC = "::::MAGIC::::";
String VALUE_TO_ENCRYPT = "my secret key goes here";
println(new String(Base64.encode(cipher.doFinal((VALUE_TO_ENCRYPT + MAGIC).getBytes("UTF-8")))));
=========================
ruby_block "something" do
block do
#tricky way to load this Chef::Mixin::ShellOut utilities
Chef::Resource::RubyBlock.send(:include, Chef::Mixin::ShellOut)
command = 'cat /etc/hostname'
command_out = shell_out(command)
node.set['my_attribute'] = command_out.stdout
end
action :create
end
=========================
UNENC_PW="admin"
cat <<EOF | java -jar /opt/jenkins-cli.jar -s http://localhost:8080 groovy =
import com.trilead.ssh2.crypto.Base64;
import javax.crypto.Cipher;
import jenkins.security.CryptoConfidentialKey;
import hudson.util.Secret;
CryptoConfidentialKey KEY = new CryptoConfidentialKey(Secret.class.getName());
Cipher cipher = KEY.encrypt();
String MAGIC = "::::MAGIC::::";
String VALUE_TO_ENCRYPT = "$UNENC_PW";
println(new String(Base64.encode(cipher.doFinal((VALUE_TO_ENCRYPT + MAGIC).getBytes("UTF-8")))));
EOF
=========================