简体   繁体   中英

What groovy cmd can I use for workstation cygwin and bash outside Jenkins?

I've got a CD pipeline running on Jenkins with some decryption code that uses base64 and gpg2 .

I set up the pipeline so that the scripts grab and decrypt the correct passwords from git using the Jenkins shell command like this:

def plainText = sh(script: """#!/bin/sh -e
        echo "$encrypted" | 
        base64 -d -w 0  | 
        gpg2 --batch --decrypt --passphrase $pw """,
    returnStdout: true
    )
println("$key=$plaintext")

The pipeline works great and now I'm looking at writing a script for our dev workstations using maven-groovy-plugin to do the same decryption locally to allow devs to run servers on workstations.

My second requirement is that I can run my maven groovy plugin on Jenkins to set up the integration testing.

So I'm looking for a solution that I can use locally and on the build server. If necessary, I could make the script switch on the OS and execute something like this:

def cmd = [ 'sh', '-c',
        """echo "$encrypted" | 
           base64 -d -w 0  | 
           gpg2 --batch --decrypt --passphrase $encryptionKey """]
cmd.execute().with {
    def output = new StringWriter()
    def error = new StringWriter()
    //wait for process ended and catch stderr and stdout.
    it.waitForProcessOutput(output, error)
    println "error=$error"
    println "output=$output"
    println "code=${it.exitValue()}"
}

but I'm not sure how to tweak the cmd to execute with cygwin .

I switched on the OS via the in-built JMX stuff and used either cygwin or linux:

import java.lang.management.*

def os = ManagementFactory.operatingSystemMXBean
println """OPERATING SYSTEM: 
    \tarchitecture = $os.arch
    \tname = $os.name
    \tversion = $os.version
    \tprocessors = $os.availableProcessors"""
def bash = os.name.contains("Win") ? "c:\\cygwin64\\bin\\bash" : "bash"
def cmd = [ bash, '-c',
         """echo "$encrypted" | 
            /usr/bin/base64 -d -w 0  | 
            /usr/bin/gpg2 --batch --decrypt --passphrase $encryptionKey """]
cmd.execute()...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM