This is the first day of my participation in the Challenge. For details, see:More article challenges

I’ve been either too busy or too lazy lately, and I can’t change my laziness, but let’s do more writing during the June More Text Challenge. The main goal of this series of articles is to play with CI/ CDS for a variety of major platforms, including but not limited to Jenkins/ Drone/ GitHub/GitLab and other modern automation tools.

Those of you who wrote Jenkins Pipeline know that both Declarative and Scripted Pipelines are based on Groovy syntax, In order to write Jenkins Pipeline well, mastering basic Groovy syntax is essential, as is the environment to run Groovy scripts.

This article describes how to configure the Groovy environment on CentOS 7 and MacOS.

Its installation

The prerequisite for installing Groovy is to install the JDK and configure the JAVA_HOME environment variable.

# MacOS
brew install openjdk@8
sudo ln -sfn $(brew --prefix)/opt/openjdk@8/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk


# CentOS 7Sudo yum install -y java-1.8.0-openjdk-develCopy the code

Configure the Java environment variables

Groovy will rely on the environment variable JAVA_HOME, edit ~/.zshrc and add the following:

# MacOS export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home" export CLASSPATH="$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" # CentOS 7 export JAVA_HOME = "/ usr/lib/JVM/Java -- 1.8.0 comes with its - 1.8.0.292. B10-1. El7_9. X86_64" export CLASSPATH="$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar"Copy the code

Tip: Use which Java and ls -ln $(which Java) to find the OpenJDK installation directory. There may be multiple links.

Download the Groovy binaries

Download address: groovy.apache.org/download.ht…

The curl - LO unzip at https://groovy.jfrog.io/artifactory/dist-release-local/groovy-zips/apache-groovy-binary-3.0.8.zip Zip sudo mv groovy-3.0.8 /usr/groovylocal
Copy the code

Configure Groovy environment variables

Edit the ~/.zshrc file and add the following

Export a GROOVY_HOME = "/ usr/local/groovy - 3.0.8" export PATH = "$a GROOVY_HOME/bin: $PATH."Copy the code

Verifying the installation

Enter the command interaction environment
groovysh

# Run the groovy script
groovy SomeScript
Copy the code

Error handling

After the normal installation is complete, running Groovysh will prompt the following error:

WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file : '/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/nashorn jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/nashorn jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/jaccess jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/jaccess jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/rt jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/rt. Jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunec jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunec jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunjce_provider jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunjce_provider jar (No to file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/cldrdata jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/cldrdata jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/zipfs jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/zipfs jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/localedata jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/localedata jar (No to the file or directory) WARN [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunpkcs11 jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/sunpkcs11 jar (No to the file or directory) WARN  [org.apache.groovy.groovysh.util.PackageHelperImpl] Error opening jar file :'/ usr/local/Cellar/its @ / 1.8.0 comes with 8 + 282 / libexec/its JDK/Contents/Home/jre/lib/ext/DNSNS jar' : java.io.FileNotFoundException: /usr/local8 / / Cellar/its @ 1.8.0 comes with 282 / libexec/its JDK/Contents/Home/jre/lib/ext/DNSNS jar (No to the file or directory) Groovy Shell (3.0.8, JVM: 1.8.0_282) Type':help' or ':h' for help. ------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------- groovy:000>Copy the code

(1.8.0+282 -> 1.8.0_282); (1.8.0+282 -> 1.8.0_282);

sudo cp -r /usr/local/ Cellar/its @ 8/1.8.0 comes with + 282 / usr /localCellar/openjdk@8/1.8.0_282 sudo ln -sfn /usr/local/ Cellar/its @ 8/1.8.0 comes with _282 / usr /local/opt/openjdk@8
Copy the code

Reference documentation

  • Install Groovy – Install Binary

Personal blog

K8scat.com/posts/insta…