├── .gitignore ├── LICENSE ├── README.md ├── pom.xml ├── shots ├── custom-setup.png ├── global-var.png ├── global-var2.png ├── image2018-9-13_0-33-6.png ├── main-setup.png ├── script-running.png ├── setup-by-project.png └── userpwd.png └── src ├── main ├── java │ └── org │ │ └── jenkinsci │ │ └── plugins │ │ └── sqlplus │ │ └── script │ │ └── runner │ │ ├── EnvUtil.java │ │ ├── FileUtil.java │ │ ├── MessageUtil.java │ │ ├── NetUtil.java │ │ ├── SQLPlusRunner.java │ │ ├── SQLPlusRunnerBuilder.java │ │ ├── SQLPlusRunnerException.java │ │ └── ScriptType.java └── resources │ ├── index.jelly │ └── org │ └── jenkinsci │ └── plugins │ └── sqlplus │ └── script │ └── runner │ ├── Messages.properties │ ├── Messages_pt_BR.properties │ └── SQLPlusRunnerBuilder │ ├── config.jelly │ ├── config.properties │ ├── config_pt_BR.properties │ ├── global.jelly │ ├── global.properties │ ├── global_pt_BR.properties │ ├── help-customNLSLang.html │ ├── help-customNLSLang_pt_BR.html │ ├── help-customOracleHome.html │ ├── help-customOracleHome_pt_BR.html │ ├── help-customSQLPath.html │ ├── help-customSQLPath_pt_BR.html │ ├── help-customSQLPlusHome.html │ ├── help-customSQLPlusHome_pt_BR.html │ ├── help-customTNSAdmin.html │ ├── help-customTNSAdmin_pt_BR.html │ ├── help-debug.html │ ├── help-debug_pt_BR.html │ ├── help-globalNLSLang.html │ ├── help-globalNLSLang_pt_BR.html │ ├── help-globalOracleHome.html │ ├── help-globalOracleHome_pt_BR.html │ ├── help-globalSQLPath.html │ ├── help-globalSQLPath_pt_BR.html │ ├── help-globalSQLPlusHome.html │ ├── help-globalSQLPlusHome_pt_BR.html │ ├── help-globalTNSAdmin.html │ ├── help-globalTNSAdmin_pt_BR.html │ ├── help-hideSQLPlusVersion.html │ ├── help-hideSQLPlusVersion_pt_BR.html │ ├── help-instance.html │ ├── help-instance_pt_BR.html │ ├── help-script.html │ ├── help-scriptContent.html │ ├── help-scriptContent_pt_BR.html │ ├── help-script_pt_BR.html │ ├── help-tryToDetectOracleHome.html │ ├── help-tryToDetectOracleHome_pt_BR.html │ ├── help-user.html │ └── help-user_pt_BR.html └── test ├── java └── org │ └── jenkinsci │ └── plugins │ └── sqlplus │ └── script │ └── runner │ └── test │ ├── ExternalProgramUtil.java │ ├── TestFileUtil.java │ └── TestSQLPlus.java └── resources ├── script.sql ├── script2.sql └── script3.sql /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | target/ 3 | .project 4 | .classpath 5 | .settings 6 | work/ 7 | work1/ 8 | work2/ 9 | work3/ 10 | work4/ 11 | .factorypath 12 | .attach* 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | 26 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 27 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 28 | 29 | .idea/ 30 | .idea/**/*.xml 31 | .idea/*.xml 32 | 33 | .idea/.gitignore 34 | .idea/codeStyles/Project.xml 35 | .idea/codeStyles/codeStyleConfig.xml 36 | .idea/compiler.xml 37 | .idea/encodings.xml 38 | .idea/jarRepositories.xml 39 | .idea/misc.xml 40 | .idea/vcs.xml 41 | 42 | # User-specific stuff 43 | .idea/**/workspace.xml 44 | .idea/**/tasks.xml 45 | .idea/**/usage.statistics.xml 46 | .idea/**/dictionaries 47 | .idea/**/shelf 48 | 49 | # AWS User-specific 50 | .idea/**/aws.xml 51 | 52 | # Generated files 53 | .idea/**/contentModel.xml 54 | 55 | # Sensitive or high-churn files 56 | .idea/**/dataSources/ 57 | .idea/**/dataSources.ids 58 | .idea/**/dataSources.local.xml 59 | .idea/**/sqlDataSources.xml 60 | .idea/**/dynamic.xml 61 | .idea/**/uiDesigner.xml 62 | .idea/**/dbnavigator.xml 63 | 64 | # Gradle 65 | .idea/**/gradle.xml 66 | .idea/**/libraries 67 | 68 | # Gradle and Maven with auto-import 69 | # When using Gradle or Maven with auto-import, you should exclude module files, 70 | # since they will be recreated, and may cause churn. Uncomment if using 71 | # auto-import. 72 | # .idea/artifacts 73 | # .idea/compiler.xml 74 | # .idea/jarRepositories.xml 75 | # .idea/modules.xml 76 | # .idea/*.iml 77 | # .idea/modules 78 | # *.iml 79 | # *.ipr 80 | 81 | # CMake 82 | cmake-build-*/ 83 | 84 | # Mongo Explorer plugin 85 | .idea/**/mongoSettings.xml 86 | 87 | # File-based project format 88 | *.iws 89 | 90 | # IntelliJ 91 | out/ 92 | 93 | # mpeltonen/sbt-idea plugin 94 | .idea_modules/ 95 | 96 | # JIRA plugin 97 | atlassian-ide-plugin.xml 98 | 99 | # Cursive Clojure plugin 100 | .idea/replstate.xml 101 | 102 | # SonarLint plugin 103 | .idea/sonarlint/ 104 | 105 | # Crashlytics plugin (for Android Studio and IntelliJ) 106 | com_crashlytics_export_strings.xml 107 | crashlytics.properties 108 | crashlytics-build.properties 109 | fabric.properties 110 | 111 | # Editor-based Rest Client 112 | .idea/httpRequests 113 | 114 | # Android studio 3.1+ serialized cache file 115 | .idea/caches/build_file_checksums.ser 116 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Fernando Boaglio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SQLPlus Script Runner 2 | 3 | This plugin enables you run [Oracle SQL\*Plus](http://www.orafaq.com/wiki/SQL*Plus_FAQ) scripts on your Jenkins jobs (user defined scripts or a script inside a workspace). 4 | 5 | *Oracle SQL\*Plus installation required!* 6 | 7 | Java version: 11+ 8 | 9 | # Releases 10 | 11 | | plugin version | Java version | description | 12 | |----------------|:------------:|:-----------------------------------------------------------------------------:| 13 | | **3.x** | 11 | Java 11 + | 14 | | **2.x** | 8 | For mainly Jenkins 2.x, credentials plugins implemented and pipeline support | 15 | | **1.x** | 7 | - For Jenkins 1.x | 16 | 17 | # Quickstart 18 | 19 | All you have to do is provide a valid *ORACLE_HOME* and you are in business: 20 | 21 | ![Main Setup](shots/main-setup.png) 22 | 23 | You can run a script inside your workspace or a user defined for every job: 24 | 25 | ![Job Setup](shots/setup-by-project.png) 26 | 27 | You can check later all SQL*Plus output inside your build output: 28 | 29 | ![Script running inside a job](shots/script-running.png) 30 | 31 | Download the last release and give it a try! 32 | 33 | # Using Pipeline 34 | 35 | ## user defined script 36 | 37 | ``` 38 | node { 39 | echo 'SQLPlusRunner running user define script for system@xe' 40 | step([$class: 'SQLPlusRunnerBuilder',credentialsId:'system', instance:'xe',scriptType:'userDefined', script: '',scriptContent: 'select * from v$version']) 41 | } 42 | ``` 43 | 44 | ## file script 45 | 46 | ``` 47 | node { 48 | echo 'SQLPlusRunner running file script for system@xe' 49 | step([$class: 'SQLPlusRunnerBuilder',credentialsId:'system', instance:'xe',scriptType:'file', script: 'start.sql',scriptContent: '']) 50 | } 51 | ``` 52 | 53 | ### Optional parameters 54 | 55 | | parameter | type | description | sample | 56 | |---------------------|:--------:|:--------------------------:|:-------------------------:| 57 | | customOracleHome | varchar | Custom ORACLE_HOME | C:\ORACLE\BIN | 58 | | customSQLPlusHome | varchar | Custom SQL*Plus (sqlplus/sqlplus.exe) location | C:\SQLPLUS | 59 | | customTNSAdmin | varchar | Custom TNS_ADMIN | C:\TNS | 60 | | customNLSLang | varchar | Custom customNLSLang | ENGLISH_UNITED KINGDOM.WE8ISO8859P1 | 61 | | customSQLPath | varchar | Custom SQL_PATH | C:\MYSCRIPTS | 62 | | isSysDba | boolean | Enable login AS SYSDBA | true | 63 | | isHideSQLPlusVersion | boolean | EDisable SQL*Version test | true | 64 | 65 | # Developer guide 66 | 67 | 1. Fork repository 68 | 2. Code code code 69 | 3. Run it with: 70 | 71 | * mvn clean 72 | * mvn -DskipTests package 73 | * mvn generate-sources (convert Message*.properties into Messages.java) 74 | * mvn compiler:compile 75 | * mvn -DskipTests package hpi:run 76 | 77 | 4. Try it at http://localhost:8080 78 | 5. Commit and submit pull request 79 | 80 | # Translator guide 81 | 82 | 1. Fork repository 83 | 2. Copy config.properties to config_.properties (example: config_pt_BR.properties) 84 | 3. Copy global.properties to global_.properties 85 | 4. Copy Messages.properties to Messages_.properties 86 | 5. Copy all HTML files too 87 | 6. Translate it 88 | 7. Run it with: 89 | 90 | * mvn clean -DskipTests package hpi:run 91 | 92 | 8. Try it at http://localhost:8080 93 | 9. Commit and submit pull request 94 | 95 | # Having problems? 96 | 97 | Please [open a new issue](https://github.com/jenkinsci/sqlplus-script-runner-plugin/issues/new) and inform: 98 | 99 | - Jenkins server Operation System; 100 | - Jenkins version; 101 | - Where SQLPlus Script Runner is running (local machine or agent machine); 102 | - Agent machine Operation System (if applicable); 103 | - Oracle Database version; 104 | - Oracle SQL*Plus version; 105 | - Build log with debug info enabled. 106 | 107 | 108 | ## Migration Guide from 1.x 109 | 110 | To migrate your workspace from version 2 is very simple, all you need todo is: 111 | 112 | 1. Create a credential for your user and password; 113 | 2. Edit you job configuration and select one credential; 114 | 3. Save your changes and you are good to go! 115 | 116 | # Configuration 117 | 118 | ## Global 119 | 120 | All you have to do is check the auto detect ORACLE\_HOME option ( or a valid *ORACLE\_HOME* ) and you are in business: 121 | 122 | ![](shots/main-setup.png) 123 | 124 | If you are having problems try to enable *Debug info* to see what is going on. 125 | 126 | ## By Job 127 | 128 | You can run a script inside your workspace or a user defined for every job: 129 | 130 | Version 1.x: 131 | 132 | ![](shots/custom-setup.png) 133 | 134 | Version 2.x : 135 | 136 | ![](shots/image2018-9-13_0-33-6.png) 137 | 138 | # Environment variables 139 | 140 | Pay attention to what version you are using in order to work with variables: 141 | 142 | 143 | | variable | Version 1.x | Version 2.x | 144 | |---------------------|:-----------:|:------------------------------:| 145 | | user | ok | *replaced by credentials* | 146 | | password | ok | *replaced by credentials* | 147 | | instance | ok | ok | 148 | 149 | 150 | You can use global variables for **user** and **instance**, first creating it in *Jenkins*→ *configuration* : 151 | 152 | ![](shots/global-var2.png) 153 | 154 | 155 | You *user* global variable can hold **username and password** as well like this (*username/password*): 156 | 157 | 158 | ![](shots/userpwd.png) 159 | 160 | And then using it: 161 | 162 | ![](shots/global-var.png) 163 | 164 | # Running 165 | 166 | You can check later all SQL\*Plus output inside your build output: 167 | 168 | ![](shots/script-running.png) 169 | 170 | # Reported problems 171 | 172 | ## my script takes forever to execute... 173 | 174 | *Windows* users sometimes get a running script stuck on build, even though they run everything on Oracle. 175 | 176 | In that case you should use [Build](https://wiki.jenkins.io/display/JENKINS/Build-timeout+Plugin)[Time Outplugin](https://wiki.jenkins.io/display/JENKINS/Build-timeout+Plugin) together to get everything working fine. 177 | 178 | ## I have an error ORA-???? 179 | 180 | You should try running manually SQL\*Plus before use Jenkins. 181 | 182 | Sometimes on *Linux* Jenkins has his **own** Operation System user with his own variables. 183 | 184 | ## Every time I get this error: *cannot find sqlplus * 185 | 186 | Jenkins plugin can't find SQL\*Plus executable file. 187 | 188 | You should do in this order: 189 | 190 | 1. Stop Jenkins; 191 | 2. Find where are *sqlplus executable* file (usually at **$ORACLE\_HOME**); 192 | 3. Check if they have proper permissions (*chmod 755 \**); 193 | 4. Create a global environment variable **ORACLE\_HOME** like this: 194 | **export 195 | ORACLE\_HOME=/oracle/app/oracle/product/12.1.0/dbhome\_1/ ** or 196 | **export ORACLE\_HOME=\** 197 | 198 | 5. Test your environment with: *sqlplus -v * , should return **SQL\*Plus version like SQL\*Plus: Release 12.1.0.1.0 Production** 199 | 6. Start Jenkins; 200 | 7. Use the try to detect **ORACLE\_HOME** option; 201 | 8. Retry your SQL\*Plus operation. 202 | 203 | ## Every time I get this error: *libsqlplus.so: cannot open shared object file: No such file or directory* or *SP2-0667: Message file sp1.msb* not found 204 | 205 | SQL\*Plus need its library and its message file to work properly. 206 | 207 | You should do in this order: 208 | 209 | 1. Stop Jenkins; 210 | 2. Find where are *libsqlplus.so* files (usually at **$ORACLE\_HOME\\lib** ); 211 | 3. Check if they have proper permissions (*chmod 755 \**); 212 | 4. Create a global environment variable **LD\_LIBRARY\_PATH** like this: 213 | **export LD\_LIBRARY\_PATH=$ORACLE\_HOME/lib:$LD\_LIBRARY\_PATH ** 214 | or **export 215 | LD\_LIBRARY\_PATH=\:$LD\_LIBRARY\_PATH** 216 | 217 | 5. Test your environment with: *sqlplus -v * , should return 218 | **SQL\*Plus version like SQL\*Plus: Release 12.1.0.1.0 Production** 219 | 220 | 6. Start Jenkins; 221 | 222 | 7. Use the try to detect **ORACLE\_HOME** option; 223 | 224 | 8. Retry your SQL\*Plus operation. 225 | 226 | ## I want to hide my user / password from Console Output 227 | 228 | 1. Install [Mask Passwords Plugin](https://wiki.jenkins.io/display/JENKINS/Mask%2BPasswords%2BPlugin); 229 | 230 | 2. Setup to hide everything you want. 231 | 232 | # I have a bug to report 233 | 234 | Please [open a newissue](https://github.com/jenkinsci/sqlplus-script-runner-plugin/issues/new) and inform: 235 | 236 | - sqlplus-script-runner-plugin version; 237 | - Jenkins server Operation System; 238 | - Jenkins version ; 239 | - Where SQLPlus Script Runner is running (*local* machine or *slave* 240 | machine); 241 | - Slave machine Operation System (if applicable); 242 | - Oracle Database version; 243 | - Oracle SQL\*Plus version; 244 | - Build log with debug info enabled. 245 | 246 | 247 | 248 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | org.jenkins-ci.plugins 7 | plugin 8 | 4.72 9 | 10 | 11 | sqlplus-script-runner 12 | 3.0.2-SNAPSHOT 13 | hpi 14 | SQLPlus Script Runner 15 | Run SQLPlus scripts on Jenkins 16 | https://github.com/jenkinsci/sqlplus-script-runner-plugin 17 | 18 | 2013 19 | 20 | 21 | UTF-8 22 | 11 23 | 11 24 | 2.414.2 25 | 26 | 27 | 28 | 29 | MIT License 30 | https://opensource.org/licenses/MIT 31 | 32 | 33 | 34 | 35 | boaglio 36 | Fernando Boaglio 37 | boaglio@gmail.com 38 | 39 | 40 | 41 | scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git 42 | scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git 43 | https://github.com/jenkinsci/${project.artifactId}-plugin 44 | sqlplus-script-runner-3.0.0 45 | 46 | 47 | 48 | repo.jenkins-ci.org 49 | https://repo.jenkins-ci.org/public/ 50 | 51 | 52 | 53 | 54 | repo.jenkins-ci.org 55 | https://repo.jenkins-ci.org/public/ 56 | 57 | 58 | 59 | 60 | 61 | org.jenkins-ci.plugins 62 | credentials 63 | 1371.1373.v4eb_fa_b_7161e9 64 | 65 | 66 | org.jenkins-ci.plugins.workflow 67 | workflow-step-api 68 | 2.4 69 | 70 | 71 | 72 | 73 | 74 | 75 | org.jenkins-ci.tools 76 | maven-hpi-plugin 77 | 78 | localhost 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-compiler-plugin 84 | 85 | 11 86 | 11 87 | 88 | 89 | 90 | com.google.code.findbugs 91 | annotations 92 | 3.0.1 93 | 94 | 95 | org.codehaus.mojo 96 | build-helper-maven-plugin 97 | 98 | 99 | add-source 100 | generate-sources 101 | 102 | add-source 103 | 104 | 105 | 106 | ${project.build.directory}/generated-sources/java/ 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /shots/custom-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/custom-setup.png -------------------------------------------------------------------------------- /shots/global-var.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/global-var.png -------------------------------------------------------------------------------- /shots/global-var2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/global-var2.png -------------------------------------------------------------------------------- /shots/image2018-9-13_0-33-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/image2018-9-13_0-33-6.png -------------------------------------------------------------------------------- /shots/main-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/main-setup.png -------------------------------------------------------------------------------- /shots/script-running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/script-running.png -------------------------------------------------------------------------------- /shots/setup-by-project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/setup-by-project.png -------------------------------------------------------------------------------- /shots/userpwd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/sqlplus-script-runner-plugin/c84769e4cb3f3589944c38c3c710fbae03d45440/shots/userpwd.png -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/EnvUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | import java.io.IOException; 4 | 5 | import hudson.Launcher; 6 | import hudson.model.Run; 7 | import hudson.model.TaskListener; 8 | import hudson.remoting.LocalChannel; 9 | import hudson.remoting.VirtualChannel; 10 | 11 | public class EnvUtil { 12 | 13 | private static final String WINDOWS_OS = "win"; 14 | 15 | private static final String OPERATION_SYSTEM = "os.name"; 16 | 17 | private static final String OPERATION_SYSTEM_AGENT = "OS"; 18 | 19 | public static boolean isAgentMachine(Launcher launcher) { 20 | VirtualChannel vc = launcher.getChannel(); 21 | return !(vc instanceof LocalChannel); 22 | } 23 | 24 | public static boolean isWindowsOS(boolean agentMachine,TaskListener listener,Run build) throws IOException, InterruptedException { 25 | 26 | boolean isWindows = false; 27 | 28 | if (agentMachine) { 29 | String osAgent = build.getEnvironment(listener).get(OPERATION_SYSTEM_AGENT); 30 | if (osAgent != null) { 31 | isWindows = osAgent.toLowerCase().contains(WINDOWS_OS); 32 | } 33 | } else { 34 | String osMaster = System.getProperty(OPERATION_SYSTEM); 35 | if (osMaster != null) { 36 | isWindows = osMaster.toLowerCase().contains(WINDOWS_OS); 37 | } 38 | } 39 | 40 | return isWindows; 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/FileUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.InputStreamReader; 8 | import java.io.Reader; 9 | import java.nio.charset.StandardCharsets; 10 | 11 | import hudson.FilePath; 12 | import hudson.model.Run; 13 | 14 | public class FileUtil { 15 | 16 | private static final int SQLPLUS_STR_LENGTH = 5; 17 | private static final String LAST_CMD_BEFORE_EXIT = "\n;\n"; 18 | private static final String SQLPLUS_EXIT = "exit;"; 19 | private static final String SQL_TEMP_SCRIPT = "temp-script-"; 20 | private static final String SQL_PREFIX = ".sql"; 21 | 22 | private FileUtil() { 23 | } 24 | 25 | public static boolean hasExitCode(FilePath filePath) throws IOException, InterruptedException { 26 | 27 | boolean found = false; 28 | 29 | InputStream in = filePath.read(); 30 | Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8); 31 | BufferedReader br = new BufferedReader(reader); 32 | 33 | String lastLine = ""; 34 | String line; 35 | while ((line = br.readLine()) != null) { 36 | if (line.length() >= SQLPLUS_STR_LENGTH) 37 | lastLine = line; 38 | } 39 | 40 | if (lastLine.trim().equalsIgnoreCase(SQLPLUS_EXIT)) 41 | found = true; 42 | 43 | br.close(); 44 | reader.close(); 45 | in.close(); 46 | 47 | return found; 48 | } 49 | 50 | public static void addExit(String content, FilePath filePath) throws IOException, InterruptedException { 51 | 52 | if (content != null) 53 | filePath.write(content + LAST_CMD_BEFORE_EXIT + SQLPLUS_EXIT, StandardCharsets.UTF_8.name()); 54 | 55 | } 56 | 57 | public static void addExitInTheEnd(FilePath filePath) throws IOException, InterruptedException { 58 | 59 | String content = filePath.readToString(); 60 | filePath.write(content + LAST_CMD_BEFORE_EXIT + SQLPLUS_EXIT, StandardCharsets.UTF_8.name()); 61 | 62 | } 63 | 64 | @SuppressWarnings("static-access") 65 | public static FilePath createTempScript(Run build, FilePath workspace, String content, boolean agentMachine) 66 | throws IOException, InterruptedException { 67 | 68 | FilePath filePath; 69 | 70 | if (agentMachine) { 71 | filePath = workspace.createTempFile(SQL_TEMP_SCRIPT + System.currentTimeMillis(), SQL_PREFIX); 72 | } else { 73 | filePath = new FilePath(build.getRootDir().createTempFile(SQL_TEMP_SCRIPT + System.currentTimeMillis(), SQL_PREFIX)); 74 | } 75 | 76 | filePath.write(content, StandardCharsets.UTF_8.name()); 77 | 78 | if (!FileUtil.hasExitCode(filePath)) 79 | addExit(content, filePath); 80 | 81 | return filePath; 82 | 83 | } 84 | 85 | public static boolean findFile(String name, File file) { 86 | 87 | boolean found = false; 88 | File[] list = file.listFiles(); 89 | if (list != null) 90 | for (File fil : list) { 91 | if (fil.isDirectory()) { 92 | findFile(name, fil); 93 | } else if (name.equalsIgnoreCase(fil.getName())) { 94 | found = true; 95 | } 96 | } 97 | return found; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/MessageUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | public class MessageUtil { 4 | 5 | // console messages 6 | public static final String MSG_TEMP_SCRIPT = Messages.SQLPlusRunner_tempScript(); 7 | public static final String ON = Messages.SQLPlusRunner_on(); 8 | public static final String FOUND_SQL_PLUS_ON = "found SQL*Plus on "; 9 | public static final String WINDOWS_FILE_SEPARATOR = "\\"; 10 | public static final String MSG_ORACLE_HOME = Messages.SQLPlusRunner_usingOracleHome(); 11 | public static final String MSG_SCRIPT = Messages.SQLPlusRunner_runningScript(); 12 | public static final String MSG_DEFINED_SCRIPT = Messages.SQLPlusRunner_runningDefinedScript(); 13 | public static final String MSG_GET_ORACLE_HOME = Messages.SQLPlusRunner_gettingOracleHome(); 14 | public static final String MSG_CUSTOM_ORACLE_HOME = Messages.SQLPlusRunner_usingCustomOracleHome(); 15 | public static final String MSG_CUSTOM_SQLPLUS_HOME = Messages.SQLPlusRunner_usingCustomSQLPlusHome(); 16 | public static final String MSG_CUSTOM_TNS_ADMIN = Messages.SQLPlusRunner_usingCustomTNSAdmin(); 17 | public static final String MSG_CUSTOM_NLS_LANG = Messages.SQLPlusRunner_usingCustomNLSLang(); 18 | public static final String MSG_CUSTOM_SQLPATH = Messages.SQLPlusRunner_usingCustomSQLPath(); 19 | public static final String MSG_GLOBAL_ORACLE_HOME = Messages.SQLPlusRunner_usingGlobalOracleHome(); 20 | public static final String MSG_GLOBAL_SQLPLUS_HOME = Messages.SQLPlusRunner_usingGlobalSQLPlusHome(); 21 | public static final String MSG_GLOBAL_TNS_ADMIN = Messages.SQLPlusRunner_usingGlobalTNSAdmin(); 22 | public static final String MSG_GLOBAL_NLS_LANG = Messages.SQLPlusRunner_usingGlobalNLSLang(); 23 | public static final String MSG_GLOBAL_SQLPATH = Messages.SQLPlusRunner_usingGlobalSQLPath(); 24 | public static final String MSG_USING_DETECTED_ORACLE_HOME = Messages.SQLPlusRunner_usingDetectedOracleHome(); 25 | public static final String MSG_GLOBAL_ORACLE_HOME_SELECTED = Messages.SQLPlusRunner_globalOracleHomeSelected(); 26 | public static final String MSG_GLOBAL_SQLPLUS_HOME_SELECTED = Messages.SQLPlusRunner_globalSQLPlusHomeSelected(); 27 | public static final String MSG_GLOBAL_TNS_ADMIN_SELECTED = Messages.SQLPlusRunner_globalTNSAdminSelected(); 28 | public static final String MSG_GLOBAL_NLS_LANG_SELECTED = Messages.SQLPlusRunner_globalNLSLangSelected(); 29 | public static final String MSG_GLOBAL_SQLPATH_SELECTED = Messages.SQLPlusRunner_globalSQLPathSelected(); 30 | public static final String MSG_ERROR = Messages.SQLPlusRunner_error(); 31 | public static final String MSG_GET_SQL_PLUS_VERSION = Messages.SQLPlusRunner_gettingSQLPlusVersion(); 32 | public static final String MSG_ORACLE_HOME_MISSING = Messages.SQLPlusRunner_missingOracleHome(); 33 | public static final String MSG_TRY_DETECTED_ORACLE_HOME = Messages.SQLPlusRunner_tryToDetectOracleHome(); 34 | public static final String MSG_GLOBAL_ORACLE_HOME_SELECTED_ANYWAY = Messages.SQLPlusRunner_globalOracleHomeSelectedAnyway(); 35 | public static final String MSG_DEBUG = Messages.SQLPlusRunner_debugMsg(); 36 | public static final String MSG_WARNING= Messages.SQLPlusRunner_warningMsg(); 37 | public static final String MSG_DEBUG_DETECTED_HOST = Messages.SQLPlusRunner_debugDetectedHost(); 38 | public static final String MSG_DEBUG_AGENT_MACHINE = Messages.SQLPlusRunner_debugAgentMachine(); 39 | public static final String MSG_DEBUG_EXEC_FILE = Messages.SQLPlusRunner_debugExecFile(); 40 | public static final String MSG_DEBUG_EXEC_DIR = Messages.SQLPlusRunner_debugExecDir(); 41 | public static final String MSG_DEBUG_TEST_DIR = Messages.SQLPlusRunner_debugTestDir(); 42 | public static final String MSG_DEBUG_TEST_SCRIPT = Messages.SQLPlusRunner_debugTestScript(); 43 | public static final String MSG_DEBUG_WORK_DIR = Messages.SQLPlusRunner_debugWorkDir(); 44 | public static final String MSG_DEBUG_STATEMENT = Messages.SQLPlusRunner_debugStatement(); 45 | public static final String MSG_DEBUG_ENV_ORACLE_HOME = Messages.SQLPlusRunner_debugEnvOracleHome(); 46 | public static final String MSG_DEBUG_ENV_LD_LIBRARY_PATH= Messages.SQLPlusRunner_debugEnvLDLibraryPath(); 47 | public static final String MSG_DEBUG_ENV_TNS_ADMIN = Messages.SQLPlusRunner_debugEnvTNSAdmin(); 48 | public static final String MSG_DEBUG_ENV_NLS_LANG = Messages.SQLPlusRunner_debugEnvNLSLang(); 49 | public static final String MSG_DEBUG_ENV_SQLPATH = Messages.SQLPlusRunner_debugEnvSQLPath(); 50 | public static final String MSG_DEBUG_FOUND_TNSNAMES = Messages.SQLPlusRunner_debugFoundTnsNames(); 51 | public static final String MSG_EXIT_CODE = Messages.SQLPlusRunner_exitCode(); 52 | public static final String MSG_EQUALS = " = "; 53 | public static final String MSG_SPACE = " "; 54 | public static final String MSG_COLON = ": "; 55 | public static final String LOCAL_DATABASE_MSG = "local"; 56 | public static final String HIDDEN_PASSWORD = "********"; 57 | public static final String LINE = Messages.SQLPlusRunner_line(); 58 | 59 | // for executing commands 60 | public static final String AT = "@"; 61 | public static final String SLASH = "/"; 62 | public static final String DOUBLE_QUOTES = "\""; 63 | 64 | // for variables 65 | public static final String ENV_LD_LIBRARY_PATH = "LD_LIBRARY_PATH"; 66 | public static final String ENV_ORACLE_HOME = "ORACLE_HOME"; 67 | public static final String ENV_TNS_ADMIN = "TNS_ADMIN"; 68 | public static final String ENV_NLS_LANG = "NLS_LANG"; 69 | public static final String ENV_SQLPATH = "SQLPATH"; 70 | 71 | // for SQL*Plus 72 | public static final String SQLPLUS_TRY_LOGIN_JUST_ONCE = "-L"; 73 | public static final String SQLPLUS_VERSION = "-v"; 74 | public static final String SQLPLUS = "sqlplus"; 75 | public static final String SQLPLUS_FOR_WINDOWS = "sqlplus.exe"; 76 | public static final String LIB_DIR = "lib"; 77 | public static final String BIN_DIR = "bin"; 78 | public static final String NET_DIR = "network"; 79 | public static final String NET_ADM_DIR = "admin"; 80 | public static final String TNSNAMES_ORA = "tnsnames.ora"; 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/NetUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | import java.net.InetAddress; 4 | import java.net.UnknownHostException; 5 | 6 | public class NetUtil { 7 | 8 | private NetUtil() { 9 | } 10 | 11 | public static String getHostName() { 12 | 13 | try { 14 | InetAddress addr = InetAddress.getLocalHost(); 15 | 16 | String ipAddress = addr.getHostAddress(); 17 | 18 | String fullyQualifiedDomainName = addr.getCanonicalHostName(); 19 | 20 | if (fullyQualifiedDomainName == null) { 21 | return ipAddress; 22 | } 23 | 24 | return fullyQualifiedDomainName; 25 | 26 | } catch (UnknownHostException e) { 27 | return "localhost"; 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunner.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | import java.io.Serializable; 8 | import java.util.Objects; 9 | 10 | import hudson.EnvVars; 11 | import hudson.FilePath; 12 | import hudson.Launcher; 13 | import hudson.model.Run; 14 | import hudson.model.TaskListener; 15 | import hudson.util.ArgumentListBuilder; 16 | 17 | /** 18 | * Run SQLPlus commands on the agent, or master of Jenkins. 19 | */ 20 | public class SQLPlusRunner implements Serializable { 21 | 22 | private static final long serialVersionUID = -2426963507463371935L; 23 | 24 | private static final int PROCESS_EXIT_CODE_SUCCESSFUL = 0; 25 | 26 | private static final String LOGON_AS_SYSDBA = "AS SYSDBA"; 27 | 28 | public SQLPlusRunner(Run build, TaskListener listener, Launcher launcher, FilePath workspace, 29 | boolean isHideSQLPlusVersion, String user, String password, boolean isSysdba, String instance, String script, 30 | String globalOracleHome, String globalSQLPlusHome, String globalTNSAdmin, String globalNLSLang, String globalSQLPath, String scriptType, 31 | String customOracleHome, String customSQLPlusHome, String customTNSAdmin, String customNLSLang, 32 | String customSQLPath, boolean tryToDetectOracleHome, boolean debug) { 33 | this.build = build; 34 | this.listener = listener; 35 | this.launcher = launcher; 36 | this.workspace = workspace; 37 | this.isHideSQLPlusVersion = isHideSQLPlusVersion; 38 | this.user = user; 39 | this.password = password; 40 | this.instance = instance; 41 | this.isSysdba= isSysdba; 42 | this.script = script; 43 | this.globalOracleHome = globalOracleHome; 44 | this.globalSQLPlusHome = globalSQLPlusHome; 45 | this.globalTNSAdmin = globalTNSAdmin; 46 | this.globalNLSLang = globalNLSLang; 47 | this.globalSQLPath = globalSQLPath; 48 | this.scriptType = scriptType; 49 | this.customOracleHome = customOracleHome; 50 | this.customSQLPlusHome = customSQLPlusHome; 51 | this.customTNSAdmin = customTNSAdmin; 52 | this.customNLSLang = customNLSLang; 53 | this.customSQLPath = customSQLPath; 54 | this.tryToDetectOracleHome = tryToDetectOracleHome; 55 | this.debug = debug; 56 | } 57 | 58 | private final Run build; 59 | 60 | private final TaskListener listener; 61 | 62 | private final Launcher launcher; 63 | 64 | private final FilePath workspace; 65 | 66 | private final boolean isHideSQLPlusVersion; 67 | 68 | private final String user; 69 | 70 | private final String password; 71 | 72 | private final String instance; 73 | 74 | private final boolean isSysdba; 75 | 76 | private final String script; 77 | 78 | private final String globalOracleHome; 79 | 80 | private final String globalSQLPlusHome; 81 | 82 | private final String globalTNSAdmin; 83 | 84 | private final String globalNLSLang; 85 | 86 | private final String globalSQLPath; 87 | 88 | private final String customOracleHome; 89 | 90 | private String customSQLPlusHome; 91 | 92 | private String customTNSAdmin; 93 | 94 | private String customNLSLang; 95 | 96 | private String customSQLPath; 97 | 98 | private final String scriptType; 99 | 100 | private final boolean tryToDetectOracleHome; 101 | 102 | private final boolean debug; 103 | 104 | /** 105 | * Get SQL Plus version 106 | * 107 | * @param customSQLPlusHome - custom SQL*Plus home 108 | * @param oracleHome - Oracle Home 109 | * @param listener - Jenkins listener 110 | * @param launcher - Jenkins launcher 111 | */ 112 | public void runGetSQLPLusVersion(String customSQLPlusHome, String oracleHome, TaskListener listener,Launcher launcher) { 113 | 114 | if (Objects. isNull(oracleHome ) || oracleHome.isEmpty()) { 115 | throw new RuntimeException(MessageUtil.MSG_ORACLE_HOME_MISSING); 116 | } 117 | 118 | boolean agentMachine = EnvUtil.isAgentMachine(launcher); 119 | if (debug) { 120 | log(MessageUtil.MSG_DEBUG_DETECTED_HOST + MessageUtil.MSG_EQUALS + NetUtil.getHostName()); 121 | log(MessageUtil.MSG_DEBUG_AGENT_MACHINE + MessageUtil.MSG_COLON + agentMachine); 122 | } 123 | 124 | boolean hasCustomSQLPlusHome = customSQLPlusHome != null && customSQLPlusHome.length() > 0; 125 | 126 | if (!agentMachine && !hasCustomSQLPlusHome) { 127 | File directoryAccessTest = new File(oracleHome); 128 | if (!directoryAccessTest.exists()) { 129 | throw new RuntimeException(Messages.SQLPlusRunner_wrongOracleHome(oracleHome)); 130 | } 131 | } 132 | 133 | line(); 134 | log(MessageUtil.MSG_ORACLE_HOME + oracleHome); 135 | line(); 136 | log(MessageUtil.MSG_GET_SQL_PLUS_VERSION); 137 | try { 138 | String sqlplus = MessageUtil.SQLPLUS; 139 | String fileSeparator = File.separator; 140 | if (EnvUtil.isWindowsOS(agentMachine, listener, build)) { 141 | sqlplus = MessageUtil.SQLPLUS_FOR_WINDOWS; 142 | fileSeparator = MessageUtil.WINDOWS_FILE_SEPARATOR; 143 | } 144 | 145 | EnvVars envVars = new EnvVars(); 146 | envVars.put(MessageUtil.ENV_ORACLE_HOME, oracleHome); 147 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_ORACLE_HOME+ MessageUtil.MSG_EQUALS + oracleHome); 148 | envVars.put(MessageUtil.ENV_LD_LIBRARY_PATH, oracleHome + fileSeparator + MessageUtil.LIB_DIR); 149 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_LD_LIBRARY_PATH+ MessageUtil.MSG_EQUALS + oracleHome + fileSeparator + MessageUtil.LIB_DIR); 150 | 151 | // create command arguments 152 | ArgumentListBuilder args = new ArgumentListBuilder(); 153 | 154 | logDebug(MessageUtil.MSG_DEBUG_EXEC_FILE + MessageUtil.MSG_EQUALS + sqlplus); 155 | 156 | if (hasCustomSQLPlusHome) { 157 | args.add(customSQLPlusHome); 158 | } else { 159 | boolean findSQLPlusOnOracleHomeBin = FileUtil.findFile(sqlplus,new File(oracleHome + fileSeparator + MessageUtil.BIN_DIR)); 160 | boolean findSQLPlusOnOracleHome = FileUtil.findFile(sqlplus, new File(oracleHome)); 161 | if (findSQLPlusOnOracleHomeBin) { 162 | log(MessageUtil.FOUND_SQL_PLUS_ON + new File(oracleHome + fileSeparator + MessageUtil.BIN_DIR).getAbsolutePath()); 163 | args.add(oracleHome + fileSeparator + MessageUtil.BIN_DIR + fileSeparator + sqlplus); 164 | } else if (findSQLPlusOnOracleHome) { 165 | log(MessageUtil.FOUND_SQL_PLUS_ON + new File(oracleHome).getAbsolutePath()); 166 | args.add(oracleHome + fileSeparator + sqlplus); 167 | } else if (agentMachine) { 168 | log(MessageUtil.MSG_DEBUG_EXEC_DIR + MessageUtil.MSG_COLON + oracleHome+ fileSeparator + MessageUtil.BIN_DIR); 169 | args.add(oracleHome + fileSeparator + MessageUtil.BIN_DIR + fileSeparator + sqlplus); 170 | } else { 171 | throw new RuntimeException(Messages.SQLPlusRunner_missingSQLPlus()); 172 | } 173 | } 174 | 175 | args.add(MessageUtil.SQLPLUS_VERSION); 176 | 177 | if (debug) { 178 | line(); 179 | log(MessageUtil.MSG_DEBUG_STATEMENT + MessageUtil.MSG_COLON); 180 | for (String a : args.toList()) { 181 | listener.getLogger().print(a + MessageUtil.MSG_SPACE); 182 | } 183 | log(MessageUtil.MSG_SPACE); 184 | line(); 185 | } 186 | 187 | int exitCode; 188 | exitCode = launcher.launch().cmds(args).envs(build.getEnvironment(listener).overrideAll(envVars)).stdout(listener).pwd(workspace).join(); 189 | listener.getLogger().printf(Messages.SQLPlusRunner_processEnd() + " %d%n", exitCode); 190 | 191 | } catch (RuntimeException e) { 192 | log(MessageUtil.MSG_ERROR + e.getMessage()); 193 | throw e; 194 | } catch (Exception e) { 195 | log(MessageUtil.MSG_ERROR + e.getMessage()); 196 | throw new RuntimeException(e); 197 | } 198 | line(); 199 | } 200 | 201 | /** 202 | * Main process to run SQLPlus 203 | */ 204 | public void run() throws IOException, InterruptedException { 205 | 206 | String selectedOracleHome; 207 | String detectedOracleHome; 208 | boolean agentMachine = EnvUtil.isAgentMachine(launcher); 209 | 210 | line(); 211 | log(MessageUtil.MSG_GET_ORACLE_HOME); 212 | 213 | // custom SQLPLUS_HOME overrides file location 214 | if (Objects.nonNull(customSQLPlusHome ) && !customSQLPlusHome.isEmpty()) { 215 | log(MessageUtil.MSG_CUSTOM_SQLPLUS_HOME); 216 | log(MessageUtil.MSG_DEBUG_EXEC_DIR + MessageUtil.MSG_COLON + customSQLPlusHome); 217 | } else if ( Objects.nonNull(globalSQLPlusHome ) && !globalSQLPlusHome.isEmpty() ) { 218 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_SQLPLUS_HOME_SELECTED); 219 | line(); 220 | log(MessageUtil.MSG_GLOBAL_SQLPLUS_HOME); 221 | customSQLPlusHome = globalSQLPlusHome; 222 | } 223 | 224 | // custom TNS_ADMIN 225 | boolean hasCustomTNSAdmin = false; 226 | if (Objects.nonNull(customTNSAdmin ) && !customTNSAdmin.isEmpty()) { 227 | log(MessageUtil.MSG_CUSTOM_TNS_ADMIN); 228 | log(MessageUtil.MSG_DEBUG_ENV_TNS_ADMIN + MessageUtil.MSG_COLON + customTNSAdmin); 229 | hasCustomTNSAdmin = true; 230 | } else if (Objects.nonNull(globalTNSAdmin ) && !globalTNSAdmin.isEmpty()) { 231 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_TNS_ADMIN_SELECTED); 232 | line(); 233 | log(MessageUtil.MSG_GLOBAL_TNS_ADMIN); 234 | customTNSAdmin = globalTNSAdmin; 235 | hasCustomTNSAdmin = true; 236 | log(MessageUtil.MSG_DEBUG_ENV_TNS_ADMIN + MessageUtil.MSG_COLON + customTNSAdmin); 237 | } 238 | 239 | // custom NLS_LANG 240 | boolean hasCustomNLSLang = false; 241 | if (Objects.nonNull(customNLSLang ) && customNLSLang.isEmpty()) { 242 | log(MessageUtil.MSG_CUSTOM_NLS_LANG); 243 | log(MessageUtil.MSG_DEBUG_ENV_NLS_LANG + MessageUtil.MSG_COLON + customNLSLang); 244 | hasCustomNLSLang = true; 245 | } else if (Objects.nonNull(globalNLSLang ) && !globalNLSLang.isEmpty()) { 246 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_NLS_LANG_SELECTED); 247 | line(); 248 | log(MessageUtil.MSG_GLOBAL_NLS_LANG); 249 | customNLSLang = globalNLSLang; 250 | hasCustomNLSLang = true; 251 | log(MessageUtil.MSG_DEBUG_ENV_NLS_LANG + MessageUtil.MSG_COLON + customNLSLang); 252 | } 253 | 254 | // custom SQLPATH 255 | boolean hasCustomSQLPath = false; 256 | if (Objects.nonNull(customSQLPath) && !customSQLPath.isEmpty()) { 257 | log(MessageUtil.MSG_CUSTOM_SQLPATH); 258 | log(MessageUtil.MSG_DEBUG_ENV_SQLPATH + MessageUtil.MSG_COLON + customSQLPath); 259 | hasCustomSQLPath = true; 260 | } else if (Objects.nonNull(globalSQLPath ) && !globalSQLPath.isEmpty()) { 261 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_SQLPATH_SELECTED); 262 | line(); 263 | log(MessageUtil.MSG_GLOBAL_SQLPATH); 264 | customSQLPath = globalSQLPath; 265 | hasCustomSQLPath = true; 266 | log(MessageUtil.MSG_DEBUG_ENV_SQLPATH + MessageUtil.MSG_COLON + customSQLPath); 267 | } 268 | 269 | // custom ORACLE_HOME overrides everything 270 | detectedOracleHome = build.getEnvironment(listener).get(MessageUtil.ENV_ORACLE_HOME); 271 | if (Objects.nonNull(customOracleHome )&& !customOracleHome.isEmpty()) { 272 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_CUSTOM_ORACLE_HOME); 273 | line(); 274 | log(MessageUtil.MSG_CUSTOM_ORACLE_HOME); 275 | selectedOracleHome = customOracleHome; 276 | // global ORACLE_HOME comes next 277 | } else if (Objects.nonNull(globalOracleHome ) && !globalOracleHome.isEmpty()) { 278 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_ORACLE_HOME_SELECTED); 279 | line(); 280 | log(MessageUtil.MSG_GLOBAL_ORACLE_HOME); 281 | selectedOracleHome = globalOracleHome; 282 | // now try to detect ORACLE_HOME 283 | } else if (tryToDetectOracleHome && Objects.nonNull(detectedOracleHome)) { 284 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_TRY_DETECTED_ORACLE_HOME); 285 | line(); 286 | log(MessageUtil.MSG_USING_DETECTED_ORACLE_HOME); 287 | selectedOracleHome = detectedOracleHome; 288 | } else { 289 | // nothing works, get global ORACLE_HOME 290 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_GLOBAL_ORACLE_HOME_SELECTED_ANYWAY); 291 | selectedOracleHome = globalOracleHome; 292 | } 293 | 294 | if (!isHideSQLPlusVersion) { 295 | runGetSQLPLusVersion(customSQLPlusHome, selectedOracleHome, listener, launcher); 296 | } 297 | 298 | logDebug(MessageUtil.MSG_DEBUG_DETECTED_HOST + MessageUtil.MSG_EQUALS + NetUtil.getHostName()); 299 | 300 | // can't find Oracle Home! 301 | if (Objects. isNull(selectedOracleHome) || selectedOracleHome.isEmpty()) { 302 | throw new RuntimeException(MessageUtil.MSG_ORACLE_HOME_MISSING); 303 | } 304 | 305 | // finding SQL*Plus 306 | boolean hasCustomSQLPlusHome = Objects.nonNull(customSQLPlusHome) && !customSQLPlusHome.isEmpty(); 307 | 308 | if (!agentMachine && !hasCustomSQLPlusHome) { 309 | File directoryAccessTest = new File(selectedOracleHome); 310 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_TEST_DIR+ MessageUtil.MSG_COLON + directoryAccessTest.getAbsolutePath()); 311 | if (!directoryAccessTest.exists()) { 312 | throw new RuntimeException(Messages.SQLPlusRunner_wrongOracleHome(selectedOracleHome)); 313 | } 314 | } 315 | 316 | // validating SQL script name 317 | if (Objects. isNull(script) || script.isEmpty()) { 318 | line(); 319 | log(MessageUtil.MSG_WARNING + Messages.SQLPlusRunner_missingScript(workspace)); 320 | line(); 321 | } 322 | 323 | String instanceStr = MessageUtil.LOCAL_DATABASE_MSG; 324 | if (Objects.nonNull(instance )) { 325 | instanceStr = instance; 326 | } 327 | 328 | line(); 329 | log(MessageUtil.MSG_ORACLE_HOME + selectedOracleHome); 330 | line(); 331 | 332 | String sqlplus = MessageUtil.SQLPLUS; 333 | String fileSeparator = File.separator; 334 | if (EnvUtil.isWindowsOS(agentMachine, listener, build)) { 335 | sqlplus = MessageUtil.SQLPLUS_FOR_WINDOWS; 336 | fileSeparator = MessageUtil.WINDOWS_FILE_SEPARATOR; 337 | } 338 | 339 | FilePath tempScript = null; 340 | FilePath scriptFilePath = null; 341 | // user defined SQL 342 | if (ScriptType.userDefined.name().equals(scriptType)) { 343 | log(MessageUtil.MSG_DEFINED_SCRIPT + MessageUtil.MSG_SPACE + user+ MessageUtil.SLASH + MessageUtil.HIDDEN_PASSWORD + MessageUtil.AT + instanceStr); 344 | scriptFilePath = FileUtil.createTempScript(build, workspace, script, agentMachine); 345 | tempScript = scriptFilePath; 346 | log(MessageUtil.MSG_TEMP_SCRIPT + MessageUtil.MSG_SPACE + scriptFilePath.absolutize().toURI()); 347 | } else { 348 | // file script 349 | String strScript = null; 350 | if (agentMachine) { 351 | if (hasCustomSQLPath) { 352 | scriptFilePath = new FilePath(new File(customSQLPath + fileSeparator + script)); 353 | } else { 354 | scriptFilePath = new FilePath(new File(workspace.getRemote() + fileSeparator + script)); 355 | } 356 | } else { 357 | if (hasCustomSQLPath) { 358 | strScript = customSQLPath + fileSeparator + script; 359 | scriptFilePath = new FilePath(new File(strScript)); 360 | } else if (Objects.nonNull(workspace )) { 361 | strScript = workspace + fileSeparator + script; 362 | scriptFilePath = new FilePath(new File(strScript)); 363 | } 364 | } 365 | 366 | if (Objects.nonNull(scriptFilePath)) 367 | log(MessageUtil.MSG_SCRIPT + MessageUtil.MSG_SPACE + scriptFilePath.getRemote()+ MessageUtil.MSG_SPACE + MessageUtil.ON + MessageUtil.MSG_SPACE + user+ MessageUtil.SLASH + MessageUtil.HIDDEN_PASSWORD + MessageUtil.AT + instanceStr); 368 | 369 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_TEST_SCRIPT+ MessageUtil.MSG_COLON + Objects.requireNonNull(scriptFilePath).getRemote()); 370 | if (!agentMachine && !scriptFilePath.exists()) { 371 | line(); 372 | log(MessageUtil.MSG_WARNING + Messages.SQLPlusRunner_missingScript(scriptFilePath.getRemote())); 373 | line(); 374 | } else { 375 | if (!agentMachine && scriptFilePath.exists() && !FileUtil.hasExitCode(scriptFilePath)) 376 | FileUtil.addExitInTheEnd(scriptFilePath); 377 | } 378 | } 379 | 380 | line(); 381 | 382 | // running script 383 | int exitCode; 384 | try { 385 | // calculating environment variables 386 | EnvVars envVars = new EnvVars(); 387 | if (hasCustomNLSLang) 388 | envVars.put(MessageUtil.ENV_NLS_LANG, customNLSLang); 389 | if (hasCustomSQLPath) 390 | envVars.put(MessageUtil.ENV_SQLPATH, customSQLPath); 391 | 392 | envVars.put(MessageUtil.ENV_ORACLE_HOME, selectedOracleHome); 393 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_ORACLE_HOME+ MessageUtil.MSG_EQUALS + selectedOracleHome); 394 | envVars.put(MessageUtil.ENV_LD_LIBRARY_PATH, selectedOracleHome + fileSeparator + MessageUtil.LIB_DIR + File.pathSeparator + selectedOracleHome); 395 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_LD_LIBRARY_PATH+ MessageUtil.MSG_EQUALS + selectedOracleHome + fileSeparator + MessageUtil.LIB_DIR+ File.pathSeparator + selectedOracleHome); 396 | 397 | if (hasCustomTNSAdmin && !agentMachine) { 398 | envVars.put(MessageUtil.ENV_TNS_ADMIN, customTNSAdmin); 399 | boolean findTNSNAMES = FileUtil.findFile(MessageUtil.TNSNAMES_ORA, new File(customTNSAdmin)); 400 | if (findTNSNAMES) { 401 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_FOUND_TNSNAMES+ MessageUtil.MSG_COLON + new File(customTNSAdmin).getAbsolutePath()); 402 | } else { 403 | throw new RuntimeException(Messages.SQLPlusRunner_missingTNSNAMES()); 404 | } 405 | } else if (agentMachine) { 406 | if (hasCustomTNSAdmin) 407 | envVars.put(MessageUtil.ENV_TNS_ADMIN, customTNSAdmin); 408 | else 409 | envVars.put(MessageUtil.ENV_TNS_ADMIN, selectedOracleHome); 410 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_TNS_ADMIN + MessageUtil.MSG_EQUALS + selectedOracleHome); 411 | 412 | } else { 413 | boolean findTNSNAMESOracleHome = FileUtil.findFile(MessageUtil.TNSNAMES_ORA,new File(selectedOracleHome)); 414 | final var tnsnames = new File(selectedOracleHome + fileSeparator + MessageUtil.NET_DIR + fileSeparator+ MessageUtil.NET_ADM_DIR); 415 | boolean findTNSNAMESOracleHomeNetworkAdmin = FileUtil.findFile(MessageUtil.TNSNAMES_ORA, tnsnames); 416 | if (findTNSNAMESOracleHomeNetworkAdmin) { 417 | envVars.put(MessageUtil.ENV_TNS_ADMIN, selectedOracleHome + fileSeparator + MessageUtil.NET_DIR+ fileSeparator + MessageUtil.NET_ADM_DIR); 418 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_FOUND_TNSNAMES+ MessageUtil.MSG_COLON+ tnsnames.getAbsolutePath()); 419 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_TNS_ADMIN+ MessageUtil.MSG_EQUALS + selectedOracleHome + fileSeparator+ MessageUtil.NET_DIR + fileSeparator + MessageUtil.NET_ADM_DIR); 420 | } else if (findTNSNAMESOracleHome) { 421 | envVars.put(MessageUtil.ENV_TNS_ADMIN, selectedOracleHome); 422 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_FOUND_TNSNAMES+ MessageUtil.MSG_COLON + new File(selectedOracleHome).getAbsolutePath()); 423 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.MSG_DEBUG_ENV_TNS_ADMIN + MessageUtil.MSG_EQUALS + selectedOracleHome); 424 | } else { 425 | throw new RuntimeException(Messages.SQLPlusRunner_missingTNSNAMES()); 426 | } 427 | } 428 | 429 | // create command arguments 430 | ArgumentListBuilder args = new ArgumentListBuilder(); 431 | String argUserPasswordInstance = user + MessageUtil.SLASH + MessageUtil.DOUBLE_QUOTES + password+ MessageUtil.DOUBLE_QUOTES; 432 | 433 | if (Objects.nonNull(instance) && !instance.trim().isEmpty()) { 434 | argUserPasswordInstance = argUserPasswordInstance + MessageUtil.AT + instance.trim(); 435 | } 436 | 437 | String argSQLscript = scriptFilePath.getRemote(); 438 | 439 | logDebug(MessageUtil.MSG_DEBUG_WORK_DIR + MessageUtil.MSG_EQUALS + workspace); 440 | 441 | if (hasCustomSQLPlusHome) { 442 | args.add(customSQLPlusHome); 443 | } else { 444 | 445 | log(MessageUtil.MSG_DEBUG_EXEC_FILE + MessageUtil.MSG_EQUALS + sqlplus); 446 | 447 | boolean findSQLPlusOnOracleHomeBin = FileUtil.findFile(sqlplus,new File(selectedOracleHome + fileSeparator + MessageUtil.BIN_DIR)); 448 | boolean findSQLPlusOnOracleHome = FileUtil.findFile(sqlplus, new File(selectedOracleHome)); 449 | 450 | if (findSQLPlusOnOracleHomeBin) { 451 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.FOUND_SQL_PLUS_ON+ new File(selectedOracleHome + fileSeparator + MessageUtil.BIN_DIR).getAbsolutePath()); 452 | args.add(selectedOracleHome + fileSeparator + MessageUtil.BIN_DIR + fileSeparator + sqlplus); 453 | } else if (findSQLPlusOnOracleHome) { 454 | logDebug(MessageUtil.MSG_DEBUG + MessageUtil.FOUND_SQL_PLUS_ON+ new File(selectedOracleHome).getAbsolutePath()); 455 | args.add(selectedOracleHome + fileSeparator + sqlplus); 456 | } else if (agentMachine) { 457 | log(MessageUtil.MSG_DEBUG_EXEC_DIR + MessageUtil.MSG_COLON + selectedOracleHome + fileSeparator + MessageUtil.BIN_DIR); 458 | args.add(selectedOracleHome + fileSeparator + MessageUtil.BIN_DIR + fileSeparator + sqlplus); 459 | } else { 460 | throw new RuntimeException(Messages.SQLPlusRunner_missingSQLPlus()); 461 | } 462 | } 463 | 464 | args.add(MessageUtil.SQLPLUS_TRY_LOGIN_JUST_ONCE); 465 | args.addMasked(argUserPasswordInstance); 466 | if (isSysdba) { 467 | args.add(LOGON_AS_SYSDBA); 468 | } 469 | args.add(MessageUtil.AT + argSQLscript); 470 | 471 | // launch SQL*Plus with arguments 472 | exitCode = launcher.launch().cmds(args).envs(build.getEnvironment(listener).overrideAll(envVars)).stdout(listener).pwd(workspace).join(); 473 | 474 | listener.getLogger().printf(Messages.SQLPlusRunner_processEnd() + " %d%n", exitCode); 475 | 476 | } catch (RuntimeException e) { 477 | throw e; 478 | } catch (Exception e) { 479 | log(MessageUtil.MSG_ERROR + e.getMessage()); 480 | throw new RuntimeException(e); 481 | } finally { 482 | if (tempScript != null) { 483 | try { 484 | boolean removed = tempScript.delete(); 485 | if (!removed) 486 | listener.getLogger().printf(Messages.SQLPlusRunner_tempFileNotRemoved()); 487 | } catch (Exception e) { 488 | log(MessageUtil.MSG_ERROR + e.getMessage()); 489 | } 490 | } 491 | } 492 | 493 | if (exitCode != PROCESS_EXIT_CODE_SUCCESSFUL) { 494 | line(); 495 | log(MessageUtil.MSG_EXIT_CODE + MessageUtil.MSG_COLON + exitCode); 496 | line(); 497 | throw new RuntimeException(Messages.SQLPlusRunner_processErrorEnd()); 498 | } 499 | 500 | line(); 501 | } 502 | 503 | private void writeObject(ObjectOutputStream stream) throws IOException { 504 | stream.defaultWriteObject(); 505 | } 506 | 507 | private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { 508 | stream.defaultReadObject(); 509 | } 510 | private void log(String message) { 511 | listener.getLogger().println(message); 512 | } 513 | private void logDebug(String message) { 514 | if (debug) 515 | log(message); 516 | } 517 | 518 | private void line() { 519 | log(MessageUtil.LINE); 520 | } 521 | 522 | } 523 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.io.ObjectOutputStream; 6 | import java.io.Serializable; 7 | import java.util.Objects; 8 | 9 | import org.jenkinsci.Symbol; 10 | import org.kohsuke.stapler.AncestorInPath; 11 | import org.kohsuke.stapler.DataBoundConstructor; 12 | import org.kohsuke.stapler.DataBoundSetter; 13 | import org.kohsuke.stapler.StaplerRequest; 14 | 15 | import com.cloudbees.plugins.credentials.Credentials; 16 | import com.cloudbees.plugins.credentials.CredentialsMatcher; 17 | import com.cloudbees.plugins.credentials.CredentialsProvider; 18 | import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials; 19 | import com.cloudbees.plugins.credentials.common.StandardUsernameListBoxModel; 20 | import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials; 21 | import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; 22 | import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; 23 | 24 | import hudson.AbortException; 25 | import hudson.EnvVars; 26 | import hudson.Extension; 27 | import hudson.FilePath; 28 | import hudson.Launcher; 29 | import hudson.model.AbstractProject; 30 | import hudson.model.Computer; 31 | import hudson.model.ItemGroup; 32 | import hudson.model.Run; 33 | import hudson.model.TaskListener; 34 | import hudson.security.ACL; 35 | import hudson.security.AccessControlled; 36 | import hudson.tasks.BuildStepDescriptor; 37 | import hudson.tasks.Builder; 38 | import hudson.util.ListBoxModel; 39 | import jenkins.model.Jenkins; 40 | import jenkins.tasks.SimpleBuildStep; 41 | import net.sf.json.JSONObject; 42 | 43 | @Symbol("sqlplusrunner") 44 | public class SQLPlusRunnerBuilder extends Builder implements SimpleBuildStep { 45 | 46 | private final String credentialsId; 47 | private final String user; 48 | private final String password; 49 | private final String isSysdba; 50 | private final String instance; 51 | private final String scriptType; 52 | private final String script; 53 | private final String scriptContent; 54 | 55 | private String customOracleHome; 56 | private String customSQLPlusHome; 57 | private String customTNSAdmin; 58 | private String customNLSLang; 59 | private String customSQLPath; 60 | 61 | @DataBoundConstructor 62 | public SQLPlusRunnerBuilder(String credentialsId, String user, String password,String isSysdba, String instance, String scriptType, String script, 63 | String scriptContent) { 64 | this.credentialsId = credentialsId; 65 | this.user = user; 66 | this.password = password; 67 | this.isSysdba = isSysdba; 68 | this.instance = instance; 69 | this.scriptType = scriptType; 70 | this.script = script; 71 | this.scriptContent = scriptContent; 72 | } 73 | 74 | public SQLPlusRunnerBuilder(String credentialsId, String user, String password, String isSysdba, String instance, String scriptType, String script, 75 | String scriptContent, String customOracleHome, String customSQLPlusHome, String customTNSAdmin,String customNLSLang,String customSQLPath) { 76 | this.credentialsId = credentialsId; 77 | this.user = user; 78 | this.password = password; 79 | this.isSysdba = isSysdba; 80 | this.instance = instance; 81 | this.scriptType = scriptType; 82 | this.script = script; 83 | this.scriptContent = scriptContent; 84 | this.customOracleHome = customOracleHome; 85 | this.customSQLPlusHome = customSQLPlusHome; 86 | this.customTNSAdmin = customTNSAdmin; 87 | this.customNLSLang = customNLSLang; 88 | this.customSQLPath = customSQLPath; 89 | } 90 | 91 | @DataBoundSetter 92 | public void setCustomOracleHome(String customOracleHome) { 93 | this.customOracleHome = customOracleHome; 94 | } 95 | 96 | @DataBoundSetter 97 | public void setCustomSQLPlusHome(String customSQLPlusHome) { 98 | this.customSQLPlusHome = customSQLPlusHome; 99 | } 100 | 101 | @DataBoundSetter 102 | public void setCustomTNSAdmin(String customTNSAdmin) { 103 | this.customTNSAdmin = customTNSAdmin; 104 | } 105 | 106 | public String getUser() { 107 | return user; 108 | } 109 | 110 | public String getPassword() { 111 | return password; 112 | } 113 | 114 | public String isSysdba() { 115 | return isSysdba; 116 | } 117 | 118 | public String getInstance() { 119 | return instance; 120 | } 121 | 122 | public String getScriptType() { 123 | return scriptType; 124 | } 125 | 126 | public String getScript() { 127 | return script; 128 | } 129 | 130 | public String getScriptContent() { 131 | return scriptContent; 132 | } 133 | 134 | public String getCustomOracleHome() { 135 | return customOracleHome; 136 | } 137 | 138 | public String getCustomSQLPlusHome() { 139 | return customSQLPlusHome; 140 | } 141 | 142 | public String getCustomTNSAdmin() { 143 | return customTNSAdmin; 144 | } 145 | 146 | public String getCustomNLSLang() { 147 | return customNLSLang; 148 | } 149 | 150 | @DataBoundSetter 151 | public void setCustomNLSLang(String customNLSLang) { 152 | this.customNLSLang = customNLSLang; 153 | } 154 | 155 | public String getCustomSQLPath() { 156 | return customSQLPath; 157 | } 158 | 159 | @DataBoundSetter 160 | public void setCustomSQLPath(String customSQLPath) { 161 | this.customSQLPath = customSQLPath; 162 | } 163 | 164 | public String getCredentialsId() { 165 | return credentialsId; 166 | } 167 | 168 | @Override 169 | public void perform(Run build, FilePath workspace, Launcher launcher, TaskListener listener) 170 | throws InterruptedException, IOException { 171 | 172 | String sqlScript; 173 | if (ScriptType.userDefined.name().equals(scriptType)) { 174 | sqlScript = scriptContent; 175 | } else { 176 | sqlScript = script; 177 | } 178 | 179 | String usr = this.user; 180 | String pwd = this.password; 181 | 182 | if(credentialsId != null){ 183 | final UsernamePasswordCredentials credentials = CredentialsProvider.findCredentialById(credentialsId, 184 | StandardUsernamePasswordCredentials.class, 185 | build, null, null); 186 | if (credentials != null){ 187 | usr = credentials.getUsername(); 188 | pwd = credentials.getPassword().getPlainText(); 189 | } 190 | } 191 | 192 | if (usr == null || pwd == null) { 193 | throw new AbortException(Messages.SQLPlusRunner_errorInvalidCredentials(credentialsId)); 194 | } 195 | 196 | boolean isConnectAsSysdba = "true".equalsIgnoreCase(isSysdba); 197 | 198 | EnvVars env = build.getEnvironment(listener); 199 | 200 | SQLPlusRunner sqlPlusRunner = new SQLPlusRunner(build, listener, launcher, workspace, 201 | getDescriptor().isHideSQLPlusVersion(), usr, pwd, isConnectAsSysdba, env.expand(instance), env.expand(sqlScript), 202 | getDescriptor().globalOracleHome, getDescriptor().globalSQLPlusHome, getDescriptor().globalTNSAdmin, getDescriptor().globalNLSLang, getDescriptor().getGlobalSQLPath(), 203 | scriptType, customOracleHome, customSQLPlusHome, customTNSAdmin, customNLSLang, customSQLPath, getDescriptor().tryToDetectOracleHome, 204 | getDescriptor().isDebug()); 205 | 206 | try { 207 | 208 | sqlPlusRunner.run(); 209 | 210 | } catch (Exception e) { 211 | 212 | e.printStackTrace(listener.getLogger()); 213 | throw new AbortException(e.getMessage()); 214 | } 215 | 216 | } 217 | 218 | @Override 219 | public DescriptorImpl getDescriptor() { 220 | return (DescriptorImpl) super.getDescriptor(); 221 | } 222 | 223 | @Extension 224 | public static final class DescriptorImpl extends BuildStepDescriptor implements Serializable { 225 | 226 | private static final long serialVersionUID = 8902135359865137242L; 227 | 228 | private static final String DISPLAY_MESSAGE = "SQLPlus Script Runner"; 229 | private static final String GLOBAL_ORACLE_HOME = "globalOracleHome"; 230 | private static final String GLOBAL_SQLPLUS_HOME = "globalSQLPlusHome"; 231 | private static final String GLOBAL_TNS_ADMIN = "globalTNSAdmin"; 232 | private static final String GLOBAL_NLS_LANG = "globalNLSLang"; 233 | private static final String GLOBAL_SQL_PATH = "globalSQLPath"; 234 | private static final String HIDE_SQL_PLUS_VERSION = "hideSQLPlusVersion"; 235 | private static final String TRY_TO_DETECT_ORACLE_HOME = "tryToDetectOracleHome"; 236 | private static final String DEBUG = "debug"; 237 | private boolean hideSQLPlusVersion; 238 | private boolean tryToDetectOracleHome; 239 | private boolean debug; 240 | private String globalOracleHome; 241 | private String globalSQLPlusHome; 242 | private String globalTNSAdmin; 243 | private String globalNLSLang; 244 | private String globalSQLPath; 245 | 246 | 247 | public DescriptorImpl() { 248 | load(); 249 | } 250 | 251 | @Override 252 | public boolean isApplicable(Class aClass) { 253 | return true; 254 | } 255 | 256 | @Override 257 | public String getDisplayName() { 258 | return DISPLAY_MESSAGE; 259 | } 260 | 261 | @Override 262 | public boolean configure(StaplerRequest req, JSONObject formData) throws FormException { 263 | hideSQLPlusVersion = formData.getBoolean(HIDE_SQL_PLUS_VERSION); 264 | globalOracleHome = formData.getString(GLOBAL_ORACLE_HOME); 265 | globalSQLPlusHome = formData.getString(GLOBAL_SQLPLUS_HOME); 266 | globalTNSAdmin = formData.getString(GLOBAL_TNS_ADMIN); 267 | globalNLSLang = formData.getString(GLOBAL_NLS_LANG); 268 | globalSQLPath = formData.getString(GLOBAL_SQL_PATH); 269 | tryToDetectOracleHome = formData.getBoolean(TRY_TO_DETECT_ORACLE_HOME); 270 | debug = formData.getBoolean(DEBUG); 271 | save(); 272 | return super.configure(req, formData); 273 | } 274 | 275 | public boolean isHideSQLPlusVersion() { 276 | return hideSQLPlusVersion; 277 | } 278 | 279 | public void setHideSQLPlusVersion(boolean hideSQLPlusVersion) { 280 | this.hideSQLPlusVersion = hideSQLPlusVersion; 281 | } 282 | 283 | public boolean isTryToDetectOracleHome() { 284 | return tryToDetectOracleHome; 285 | } 286 | 287 | public void setTryToDetectOracleHome(boolean tryToDetectOracleHome) { 288 | this.tryToDetectOracleHome = tryToDetectOracleHome; 289 | } 290 | 291 | public boolean isDebug() { 292 | return debug; 293 | } 294 | 295 | public void setDebug(boolean debug) { 296 | this.debug = debug; 297 | } 298 | 299 | public String getOracleHome() { 300 | return globalOracleHome; 301 | } 302 | 303 | public void setOracleHome(String globalOracleHome) { 304 | this.globalOracleHome = globalOracleHome; 305 | } 306 | 307 | public String getGlobalSQLPlusHome() { 308 | return globalSQLPlusHome; 309 | } 310 | 311 | public void setGlobalSQLPlusHome(String globalSQLPlusHome) { 312 | this.globalSQLPlusHome = globalSQLPlusHome; 313 | } 314 | 315 | public String getGlobalTNSAdmin() { 316 | return globalTNSAdmin; 317 | } 318 | 319 | public void setGlobalTNSAdmin(String globalTNSAdmin) { 320 | this.globalTNSAdmin = globalTNSAdmin; 321 | } 322 | 323 | public String getGlobalNLSLang() { 324 | return globalNLSLang; 325 | } 326 | 327 | public void setGlobalNLSLang(String globalNLSLang) { 328 | this.globalNLSLang = globalNLSLang; 329 | } 330 | 331 | public String getGlobalSQLPath() { 332 | return globalSQLPath; 333 | } 334 | 335 | public void setGlobalSQLPath(String globalSQLPath) { 336 | this.globalSQLPath = globalSQLPath; 337 | } 338 | 339 | public String getGlobalOracleHome() { 340 | return globalOracleHome; 341 | } 342 | 343 | public void setGlobalOracleHome(String globalOracleHome) { 344 | this.globalOracleHome = globalOracleHome; 345 | } 346 | 347 | @SuppressWarnings("deprecation") 348 | public ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) { 349 | if (!(Objects.requireNonNull(context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance())) 350 | .hasPermission(Computer.CONFIGURE)) { 351 | return new ListBoxModel(); 352 | } 353 | return new StandardUsernameListBoxModel().withMatching(new CredentialsMatcher() { 354 | private static final long serialVersionUID = 1L; 355 | 356 | @Override 357 | public boolean matches(Credentials item) { 358 | return item instanceof UsernamePasswordCredentialsImpl; 359 | } 360 | }, CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, context, ACL.SYSTEM, null, 361 | null)); 362 | } 363 | } 364 | 365 | private void writeObject(ObjectOutputStream stream) throws IOException { 366 | stream.defaultWriteObject(); 367 | } 368 | 369 | private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { 370 | stream.defaultReadObject(); 371 | } 372 | 373 | } 374 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.jenkinsci.plugins.sqlplus.script.runner; 5 | 6 | /** 7 | * {@link SQLPlusRunner} exception. 8 | */ 9 | public class SQLPlusRunnerException extends Exception { 10 | 11 | /* 12 | * serial UID. 13 | */ 14 | private static final long serialVersionUID = -8584046202815156649L; 15 | 16 | /** 17 | * Default constructor. 18 | */ 19 | public SQLPlusRunnerException() { 20 | } 21 | 22 | /** 23 | * Constructor with message. 24 | * @param message message 25 | */ 26 | public SQLPlusRunnerException(String message) { 27 | super(message); 28 | } 29 | 30 | /** 31 | * Constructor with cause. 32 | * @param cause cause 33 | */ 34 | public SQLPlusRunnerException(Throwable cause) { 35 | super(cause); 36 | } 37 | 38 | /** 39 | * Constructor with message and cause. 40 | * @param message message 41 | * @param cause cause 42 | */ 43 | public SQLPlusRunnerException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | /** 48 | * Constructor with message, cause and flags. 49 | * @param message message 50 | * @param cause cause 51 | * @param enableSuppression enable suppression flag 52 | * @param writableStackTrace writable stack trace flag 53 | */ 54 | public SQLPlusRunnerException(String message, Throwable cause, boolean enableSuppression, 55 | boolean writableStackTrace) { 56 | super(message, cause, enableSuppression, writableStackTrace); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/sqlplus/script/runner/ScriptType.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner; 2 | 3 | public enum ScriptType { 4 | file, 5 | userDefined; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 5 |
6 | This plugin allows Jenkins to run SQLPlus (or SQL*Plus) scripts on Jenkins. 7 |
8 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/Messages.properties: -------------------------------------------------------------------------------- 1 | # log 2 | SQLPlusRunner.line=-------------------------------------------------------------------------- 3 | 4 | SQLPlusRunner.gettingOracleHome=Getting ORACLE_HOME... 5 | SQLPlusRunner.usingCustomOracleHome=Using custom ORACLE_HOME 6 | SQLPlusRunner.usingGlobalOracleHome=Using global ORACLE_HOME 7 | SQLPlusRunner.usingGlobalSQLPlusHome=Using global SQL*Plus location 8 | SQLPlusRunner.usingGlobalTNSAdmin=Using global TNS_ADMIN location 9 | SQLPlusRunner.usingGlobalNLSLang=Using global NLS_LANG location 10 | SQLPlusRunner.usingGlobalSQLPath=Using global SQLPATH location 11 | SQLPlusRunner.usingCustomSQLPlusHome=Using custom SQL*Plus location 12 | SQLPlusRunner.usingCustomTNSAdmin=Using custom TNS_ADMIN location 13 | SQLPlusRunner.usingCustomNLSLang=Using custom NLS_LANG location 14 | SQLPlusRunner.usingCustomSQLPath=Using custom SQLPATH location 15 | SQLPlusRunner.usingDetectedOracleHome=Using detected ORACLE_HOME 16 | SQLPlusRunner.globalOracleHomeSelected=Global ORACLE_HOME selected 17 | SQLPlusRunner.globalSQLPlusHomeSelected=Global SQL*Plus selected 18 | SQLPlusRunner.globalTNSAdminSelected=Global TNS_ADMIN selected 19 | SQLPlusRunner.globalNLSLangSelected=Global NLS_LANG selected 20 | SQLPlusRunner.globalSQLPathSelected=Global SQLPATH selected 21 | SQLPlusRunner.tryToDetectOracleHome=Try to detect ORACLE_HOME 22 | SQLPlusRunner.globalOracleHomeSelectedAnyway=Global ORACLE_HOME selected anyway 23 | 24 | SQLPlusRunner.tempScript=Temp script: 25 | SQLPlusRunner.usingOracleHome=Using ORACLE_HOME = 26 | SQLPlusRunner.runningScript=Running script 27 | SQLPlusRunner.on=on 28 | SQLPlusRunner.runningDefinedScript=Running defined script on 29 | SQLPlusRunner.error=Error: 30 | SQLPlusRunner.gettingSQLPlusVersion=Getting SQLPlus version 31 | SQLPlusRunner.missingScript=Unable to read SQL script [{0}] ! 32 | SQLPlusRunner.missingOracleHome=Please set up the ORACLE_HOME! 33 | SQLPlusRunner.missingSQLPlus=SQL*Plus missing, please fix your ORACLE_HOME! 34 | SQLPlusRunner.missingTNSNAMES=TNSNAMES.ORA missing! 35 | SQLPlusRunner.wrongOracleHome=ORACLE_HOME directory [{0}] does not exist! 36 | 37 | SQLPlusRunner.errorLogRunner=error stdout from sqlplusrunner agent 38 | SQLPlusRunner.logRunner=log stdout from sqlplusrunner agent 39 | SQLPlusRunner.errorLogVersion=error stdout from sqlplusrunner agent for sqlplus version 40 | SQLPlusRunner.logVersion=log stdout from sqlplusrunner agent for sqlplus version 41 | SQLPlusRunner.processEnd=Process exited with status 42 | SQLPlusRunner.processErrorEnd=Process exited with error 43 | SQLPlusRunner.tempFileNotRemoved=Temporary file not removed 44 | SQLPlusRunner.errorInvalidCredentials=Invalid credentials [{0}]. Failed to initialize credentials or load user and password 45 | 46 | SQLPlusRunner.warningMsg=[WARNING] 47 | SQLPlusRunner.debugMsg=[DEBUG] 48 | SQLPlusRunner.debugDetectedHost=detected host 49 | SQLPlusRunner.debugAgentMachine=agent machine 50 | SQLPlusRunner.debugExecFile=SQL*Plus exec file 51 | SQLPlusRunner.debugExecDir=SQL*Plus directory 52 | SQLPlusRunner.debugTestDir=testing directory 53 | SQLPlusRunner.debugTestScript=testing script 54 | SQLPlusRunner.debugWorkDir=Work Directory 55 | SQLPlusRunner.debugStatement=Statement 56 | SQLPlusRunner.debugEnvOracleHome=ORACLE_HOME 57 | SQLPlusRunner.debugEnvLDLibraryPath=LD_LIBRARY_PATH 58 | SQLPlusRunner.debugEnvTNSAdmin=TNS_ADMIN 59 | SQLPlusRunner.debugEnvNLSLang=NLS_LANG 60 | SQLPlusRunner.debugEnvSQLPath=SQLPATH 61 | SQLPlusRunner.debugFoundTnsNames=found TNSNAMES.ORA on 62 | SQLPlusRunner.exitCode=Exit code -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/Messages_pt_BR.properties: -------------------------------------------------------------------------------- 1 | # log 2 | SQLPlusRunner.line=-------------------------------------------------------------------------- 3 | 4 | SQLPlusRunner.gettingOracleHome=Buscando ORACLE_HOME... 5 | SQLPlusRunner.usingCustomOracleHome=Usando ORACLE_HOME customizado 6 | SQLPlusRunner.usingGlobalOracleHome=Usando ORACLE_HOME global 7 | SQLPlusRunner.usingGlobalSQLPlusHome=Usando SQL*Plus global 8 | SQLPlusRunner.usingGlobalTNSAdmin=Usando TNS_ADMIN global 9 | SQLPlusRunner.usingGlobalNLSLang=Usando NLS_LANG global 10 | SQLPlusRunner.usingGlobalSQLPath=Usando SQLPATH global 11 | SQLPlusRunner.usingCustomSQLPlusHome=Usando local do SQL*Plus customizado 12 | SQLPlusRunner.usingCustomTNSAdmin=Usando TNS_ADMIN customizado 13 | SQLPlusRunner.usingCustomNLSLang=Usando NLS_LANG customizado 14 | SQLPlusRunner.usingCustomSQLPath=Usando SQLPATH customizado 15 | 16 | SQLPlusRunner.usingDetectedOracleHome=Usando ORACLE_HOME detectado 17 | SQLPlusRunner.globalOracleHomeSelected=Global ORACLE_HOME selecionado 18 | SQLPlusRunner.globalSQLPlusHomeSelected=Global SQL*Plus selecionado 19 | SQLPlusRunner.globalTNSAdminSelected=Global TNS_ADMIN selecionado 20 | SQLPlusRunner.globalNLSLangSelected=Global NLS_LANG selecionado 21 | SQLPlusRunner.globalSQLPathSelected=Global SQLPATH selecionado 22 | SQLPlusRunner.tryToDetectOracleHome=Tentando achar o ORACLE_HOME 23 | SQLPlusRunner.globalOracleHomeSelectedAnyway=Global ORACLE_HOME selecionado de qualquer jeito 24 | 25 | SQLPlusRunner.tempScript=Script tempor\u00e1rio: 26 | SQLPlusRunner.usingOracleHome=Usando ORACLE_HOME = 27 | SQLPlusRunner.runningScript=Rodando script 28 | SQLPlusRunner.on=em 29 | SQLPlusRunner.runningDefinedScript=Rodando script em 30 | SQLPlusRunner.error=Erro: 31 | SQLPlusRunner.gettingSQLPlusVersion=Buscando a vers\u00e3o do SQLPlus 32 | SQLPlusRunner.missingScript=N\u00e3o foi poss\u00edvel ler o script SQL [{0}] ! 33 | SQLPlusRunner.missingOracleHome=Por favor configure o ORACLE_HOME! 34 | SQLPlusRunner.missingSQLPlus=SQL*Plus n\u00e3o encontrado, por favor ajuste o ORACLE_HOME! 35 | SQLPlusRunner.missingTNSNAMES=TNSNAMES.ORA n\u00e3o encontrado! 36 | SQLPlusRunner.wrongOracleHome=O diret\u00f3rio ORACLE_HOME [{0}] n\u00e3o existe! 37 | 38 | SQLPlusRunner.errorLogRunner=log de erro do sqlplusrunner agent 39 | SQLPlusRunner.logRunner=log do sqlplusrunner agent 40 | SQLPlusRunner.errorLogVersion=log de erro do sqlplusrunner agent para vers\u00e3o do sqlplus 41 | SQLPlusRunner.logVersion=log do sqlplusrunner agent para vers\u00e3o do sqlplus 42 | SQLPlusRunner.processEnd=Processo terminou com status 43 | SQLPlusRunner.processErrorEnd=Processo terminou com erro 44 | SQLPlusRunner.tempFileNotRemoved=Arquivo tempor\u00e1rio n\u00e3o foi removido 45 | SQLPlusRunner.errorInvalidCredentials=Credenciais inv\u00e1lidas [{0}]. Falha ao informar as credenciais ou carregar usu\u00e1rio e senha 46 | 47 | SQLPlusRunner.debugMsg=[DEBUG] 48 | SQLPlusRunner.debugDetectedHost=host encontrado 49 | SQLPlusRunner.debugAgentMachine=agent machine 50 | SQLPlusRunner.debugExecFile=arquivo execut\u00e1vel do SQL*Plus 51 | SQLPlusRunner.debugExecDir=diret\u00f3rio do SQL*Plus 52 | SQLPlusRunner.debugTestDir=diret\u00f3rio de testes 53 | SQLPlusRunner.debugWorkDir=diret\u00f3rio de trabalho 54 | SQLPlusRunner.debugStatement=Comando 55 | SQLPlusRunner.debugEnvOracleHome=ORACLE_HOME 56 | SQLPlusRunner.debugEnvLDLibraryPath=LD_LIBRARY_PATH 57 | SQLPlusRunner.debugEnvTNSAdmin=TNS_ADMIN 58 | SQLPlusRunner.debugEnvNLSLang=NLS_LANG 59 | SQLPlusRunner.debugEnvSQLPath=SQLPATH 60 | SQLPlusRunner.debugFoundTnsNames=encontrado TNSNAMES.ORA em 61 | SQLPlusRunner.exitCode=Exit code -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/config.properties: -------------------------------------------------------------------------------- 1 | user=user 2 | password=password 3 | instance=instance 4 | Connect AS SYSDBA=Connect as SYSDBA 5 | Script\ Type\ to\ run=Script Type to run 6 | File\ Script=File Script 7 | User\ Defined\ Script=User Defined Script 8 | Custom\ ORACLE_HOME=Custom ORACLE_HOME 9 | Custom\ SQLPLUS_HOME=Custom SQL*Plus location (sqlplus.exe or sqlplus) 10 | Custom\ TNS_ADMIN=Custom TNS_ADMIN 11 | Custom\ NLS_LANG=Custom NLS_LANG 12 | Custom\ SQLPATH=Custom SQLPATH -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/config_pt_BR.properties: -------------------------------------------------------------------------------- 1 | user=usu\u00e1rio 2 | password=senha 3 | instance=inst\u00e2ncia 4 | Connect AS SYSDBA=Conectar como SYSDBA 5 | Script\ Type\ to\ run=Tipo de script para rodar 6 | File\ Script=Arquivo 7 | User\ Defined\ Script=Script definido pelo usu\u00e1rio 8 | Custom\ ORACLE_HOME=ORACLE_HOME customizado 9 | Custom\ SQLPLUS_HOME=Local do SQL*Plus (sqlplus.exe ou sqlplus) 10 | Custom\ TNS_ADMIN=TNS_ADMIN customizado 11 | Custom\ NLS_LANG=NLS_LANG customizado 12 | Custom\ SQLPATH=SQLPATH customizado -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/global.jelly: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/global.properties: -------------------------------------------------------------------------------- 1 | Hide\ SQLPlus\ Version=Hide SQLPlus Version 2 | Try\ to detect\ ORACLE_HOME=Try to detect ORACLE_HOME 3 | Set\ global\ ORACLE_HOME=Set global ORACLE_HOME 4 | Set\ global\ SQLPLUS_HOME=Set global SQL*Plus location (sqlplus.exe or sqlplus) 5 | Set\ global\ TNS_ADMIN=Set global TNS_ADMIN 6 | Set\ global\ NLS_LANG=Set global NLS_LANG 7 | Set\ global\ SQLPATH=Set global SQLPATH 8 | Debug=Debug info 9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/global_pt_BR.properties: -------------------------------------------------------------------------------- 1 | Hide\ SQLPlus\ Version=Esconder vers\u00e3o do SQLPlus 2 | Try\ to\ detect\ ORACLE_HOME=Tentar detectar o ORACLE_HOME 3 | Set\ global\ ORACLE_HOME=Definir ORACLE_HOME global 4 | Set\ global\ SQLPLUS_HOME=Definir localiza\u00e7\u00e3o global do SQL*Plus (sqlplus.exe ou sqlplus) 5 | Set\ global\ TNS_ADMIN=Definir TNS_ADMIN global 6 | Set\ global\ NLS_LANG=Definir NLS_LANG global 7 | Set\ global\ SQLPATH=Definir SQLPATH global 8 | Debug=Informa\u00e7\u00e3o de Debug -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customNLSLang.html: -------------------------------------------------------------------------------- 1 |
2 | NLS_LANG is an environment variable used to define language, territory and character set properties. 3 | Example: AMERICAN_AMERICA.US7ASCII or FRENCH_CANADA.WE8ISO8859P1 4 | Source: ORAFAQ 5 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customNLSLang_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Definir o parâmetro do ambiente NLS_LANG é a maneira mais simples de especificar o comportamento da localidade para o software Oracle. 3 | Ele define o idioma e o território usados pelo aplicativo cliente e pelo servidor de banco de dados, além de especificar convenções como a data padrão, 4 | os formatos monetário e numérico. 5 | Exemplo: AMERICAN_AMERICA.US7ASCII ou FRENCH_CANADA.WE8ISO8859P1 6 | Fonte: ORAFAQ 7 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customOracleHome.html: -------------------------------------------------------------------------------- 1 |
2 | Using custom ORACLE_HOME will override global ORACLE_HOME. 3 | Leave this field blank to use global ORACLE_HOME. 4 | ORACLE_HOME refers to either a directory where the Oracle software is installed or 5 | an environment variable pointing to the directory where the Oracle software is installed. 6 | Source: ORAFAQ 7 |
8 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customOracleHome_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Usando o ORACLE_HOME customizado sobrescreve o ORACLE_HOME global. 3 | Deixe esse campo em branco para usar o ORACLE_HOME global. 4 | O ORACLE_HOME referencia um diretório onde o software da Oracle está instalado ou 5 | uma variável de ambiente que aponta para esse diretório. 6 | Fonte: ORAFAQ 7 |
8 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customSQLPath.html: -------------------------------------------------------------------------------- 1 |
2 | SQLPATH contains the name of your directory for your SQL script collection. 3 | Example: c:\u01\app\sql_scripts or /oracle/app/sql 4 | Source: DBA Oracle 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customSQLPath_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | SQLPATH contém o nome do diretório para sua coleção de scripts SQL. 3 | Exemplo: c:\u01\app\sql_scripts ou /oracle/app/sql 4 | Fonte: DBA Oracle 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customSQLPlusHome.html: -------------------------------------------------------------------------------- 1 |
2 | Using custom SQL*Plus will help find SQL*Plus executable file, this helps if you are working with Jenkins agent machines. 3 | Example: C:\Oracle\App\Server\Oracle\bin\sqlplus.exe or /oracle/app/oracle/product/12.1.0/dbhome_1/bin/sqlplus 4 | Learn more about distributed builds 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customSQLPlusHome_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Especifica o caminho completo do arquivo executável do SQL*Plus, isso pode ajudar se você trabalha com máquinas agent do Jenkins. 3 | Exemplo: C:\Oracle\App\Server\Oracle\bin\sqlplus.exe ou /oracle/app/oracle/product/12.1.0/dbhome_1/bin/sqlplus 4 | Aprenda mais sobre builds distribuídos 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customTNSAdmin.html: -------------------------------------------------------------------------------- 1 |
2 | Using custom TNS_ADMIN refers to a directory where the Oracle SQL*Net configuration files (like sqlnet.ora and tnsnames.ora) are located. 3 | Example: C:\Oracle\App\Server\Oracle\network\admin or /oracle/app/oracle/product/12.1.0/dbhome_1/network/admin 4 | Source: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-customTNSAdmin_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | O TNS_ADMIN referencia um diretório onde os arquivos de configuração do Oracle SQL*Net estão localizados (exemplo: sqlnet.ora e tnsnames.ora). 3 | Exemplo: C:\Oracle\App\Server\Oracle\network\admin ou /oracle/app/oracle/product/12.1.0/dbhome_1/network/admin 4 | Fonte: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-debug.html: -------------------------------------------------------------------------------- 1 |
2 | Enable debug mode to show a lot of information about SQL*Plus and your files. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-debug_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Ative o modo debug para exibir mais informações sobre o SQL*Plus e sobre seus arquivos. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalNLSLang.html: -------------------------------------------------------------------------------- 1 |
2 | NLS_LANG is an environment variable used to define language, territory and character set properties. 3 | Example: AMERICAN_AMERICA.US7ASCII or FRENCH_CANADA.WE8ISO8859P1 4 | Source: ORAFAQ 5 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalNLSLang_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Definir o parâmetro do ambiente NLS_LANG é a maneira mais simples de especificar o comportamento da localidade para o software Oracle. 3 | Ele define o idioma e o território usados pelo aplicativo cliente e pelo servidor de banco de dados, além de especificar convenções como a data padrão, 4 | os formatos monetário e numérico. 5 | Exemplo: AMERICAN_AMERICA.US7ASCII ou FRENCH_CANADA.WE8ISO8859P1 6 | Fonte: ORAFAQ 7 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalOracleHome.html: -------------------------------------------------------------------------------- 1 |
2 | ORACLE_HOME refers to either a directory where the Oracle software is installed or 3 | an environment variable pointing to the directory where the Oracle software is installed. 4 | Source: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalOracleHome_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | O ORACLE_HOME referencia um diretório onde o software da Oracle está instalado ou 3 | uma variável de ambiente que aponta para esse diretório. 4 | Fonte: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalSQLPath.html: -------------------------------------------------------------------------------- 1 |
2 | SQLPATH contains the name of your directory for your SQL script collection. 3 | Example: c:\u01\app\sql_scripts or /oracle/app/sql 4 | Source: DBA Oracle 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalSQLPath_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | SQLPATH contém o nome do diretório para sua coleção de scripts SQL. 3 | Exemplo: c:\u01\app\sql_scripts ou /oracle/app/sql 4 | Fonte: DBA Oracle 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalSQLPlusHome.html: -------------------------------------------------------------------------------- 1 |
2 | O SQLPlus Home refers to where Oracle software SQL*Plus file is. 3 | Example: C:\oraclexe\app\oracle\product\11.2.0\server\bin\sqlplus.exe 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalSQLPlusHome_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | O SQLPlus Home referencia um diretório onde o software da Oracle está instalado o SQL*Plus. 3 | Examplo: C:\oraclexe\app\oracle\product\11.2.0\server\bin\sqlplus.exe 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalTNSAdmin.html: -------------------------------------------------------------------------------- 1 |
2 | TNS_ADMIN refers to either a directory where sqlnet.ora and tnsnames.ora files from Oracle SQL*Net are installed or 3 | an environment variable pointing to the directory where the Oracle software is installed. 4 | Fonte: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-globalTNSAdmin_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | O TNS_ADMIN referencia um diretório onde os arquivos sqlnet.ora e tnsnames.ora do Oracle SQL*Net está instalados ou 3 | uma variável de ambiente que aponta para esse diretório. 4 | Fonte: ORAFAQ 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-hideSQLPlusVersion.html: -------------------------------------------------------------------------------- 1 |
2 | SQLPlus version enabled helps detecting SQLPlus installation problems. 3 | If you environment is fine, you can check this option. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-hideSQLPlusVersion_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Com a versão do SQLPlus ativa ajuda a determinar problemas de instalação, 3 | se o ORACLE_HOME aponta para o diretório correto. 4 | Se o seu ambiente funciona corretamente, essa opção pode ser desativada. 5 |
6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-instance.html: -------------------------------------------------------------------------------- 1 |
2 | Inform instance information (example: ORCL). 3 | You can use global variable like ${INSTANCE}. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-instance_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Informe o nome da intância (exemplo: ORCL). 3 | Você pode usar uma variável global também como por exemplo ${INSTANCE}. 4 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-script.html: -------------------------------------------------------------------------------- 1 |
2 | This is the name of SQL script, expected at src/main/resources folder. 3 |
4 | Example: 5 |
6 | update.sql or sql/update.sql 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-scriptContent.html: -------------------------------------------------------------------------------- 1 |
2 | This is a custom SQL script.
3 | Example:
4 | 5 | 6 | 10 | 11 |
7 |  SELECT sysdate from dual; 
8 |  show user;  9 |
12 |
13 |
14 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-scriptContent_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Esse é um script SQL customizado.
3 | Exemplo:
4 | 5 | 6 | 10 | 11 |
7 |  SELECT sysdate from dual; 
8 |  show user;  9 |
12 |
13 |
14 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-script_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Esse é o nome do script SQL, o seu local esperado é na pasta src/main/resources. 3 |
4 | Exemplo: 5 |
6 | update.sql ou sql/update.sql 7 |
8 |
9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-tryToDetectOracleHome.html: -------------------------------------------------------------------------------- 1 |
2 | Try to detect ORACLE_HOME from system environment. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-tryToDetectOracleHome_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Tenta detectar automaticamente o ORACLE_HOME do ambiente do sistema. 3 |
4 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-user.html: -------------------------------------------------------------------------------- 1 |
2 | Inform schema user information (example: SCOTT) or schema user and password (example: SCOTT/TIGER). 3 | You can use global variable like ${USER}. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/sqlplus/script/runner/SQLPlusRunnerBuilder/help-user_pt_BR.html: -------------------------------------------------------------------------------- 1 |
2 | Informe o usuário do schema (exemplo: SCOTT) ou o usuário e senha do schema (exemplo: SCOTT/TIGER). 3 | Você pode usar uma varáivel global também como por exemplo ${USER}. 4 |
-------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/sqlplus/script/runner/test/ExternalProgramUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner.test; 2 | import java.io.BufferedReader; 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.io.Writer; 9 | import java.util.Map; 10 | 11 | import org.jenkinsci.plugins.sqlplus.script.runner.ScriptType; 12 | 13 | public class ExternalProgramUtil { 14 | 15 | private static final String EOL = "\n"; 16 | private static final String LIB_DIR = "lib"; 17 | private static final String BIN_DIR = "bin"; 18 | private static final String NET_DIR = "network" + File.separator + "admin"; 19 | private static final String ENV_LD_LIBRARY_PATH = "LD_LIBRARY_PATH"; 20 | private static final String ENV_ORACLE_HOME = "ORACLE_HOME"; 21 | private static final String ENV_TNS_ADMIN = "TNS_ADMIN"; 22 | 23 | private static final String SQLPLUS = "sqlplus"; 24 | private static final String SQLPLUS_EXIT = EOL + "exit;" + EOL + "exit;"; 25 | private static final String SQLPLUS_TRY_LOGIN_JUST_ONCE = "-L"; 26 | private static final String SQLPLUS_VERSION = "-v"; 27 | 28 | private static final String AT = "@"; 29 | private static final String SLASH = "/"; 30 | 31 | public static String run(String user,String password,String instance,String script,String sqlPath,String oracleHome,String scriptType) throws IOException,InterruptedException { 32 | 33 | String sqlplusOutput = ""; 34 | String arg1 = user + SLASH + password; 35 | 36 | if (instance != null) { 37 | arg1 = arg1 + AT + instance; 38 | } 39 | String arg2 = script; 40 | if (ScriptType.userDefined.name().equals(scriptType)) { 41 | addExitOnFile(arg2); 42 | } else { 43 | addExitOnFile(sqlPath + File.separator + arg2); 44 | } 45 | 46 | System.out.println(arg2); 47 | String line; 48 | 49 | ProcessBuilder pb = new ProcessBuilder(oracleHome + File.separator + BIN_DIR + File.separator + SQLPLUS,SQLPLUS_TRY_LOGIN_JUST_ONCE,arg1,AT + arg2); 50 | 51 | Map env = pb.environment(); 52 | env.put(ENV_ORACLE_HOME,oracleHome); 53 | env.put(ENV_LD_LIBRARY_PATH,oracleHome + File.separator + LIB_DIR); 54 | env.put(ENV_TNS_ADMIN,oracleHome + File.separator + NET_DIR); 55 | 56 | pb.directory(new File(sqlPath)); 57 | pb.redirectErrorStream(true); 58 | 59 | Process p = pb.start(); 60 | p.waitFor(); 61 | 62 | BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); 63 | 64 | while ( (line = bri.readLine()) != null) { 65 | sqlplusOutput += line + EOL; 66 | } 67 | 68 | return sqlplusOutput; 69 | } 70 | 71 | public static String getVersion(String sqlPath,String oracleHome) throws IOException,InterruptedException { 72 | 73 | String sqlplusOutput = ""; 74 | String line; 75 | 76 | ProcessBuilder pb = new ProcessBuilder(oracleHome + File.separator + BIN_DIR + File.separator + SQLPLUS,SQLPLUS_VERSION); 77 | 78 | Map env = pb.environment(); 79 | env.put(ENV_ORACLE_HOME,oracleHome); 80 | env.put(ENV_LD_LIBRARY_PATH,oracleHome + File.separator + LIB_DIR); 81 | 82 | pb.directory(new File(sqlPath)); 83 | pb.redirectErrorStream(true); 84 | 85 | Process p = pb.start(); 86 | p.waitFor(); 87 | 88 | BufferedReader bri = new BufferedReader(new InputStreamReader(p.getInputStream())); 89 | 90 | while ( (line = bri.readLine()) != null) { 91 | sqlplusOutput += line + EOL; 92 | } 93 | 94 | return sqlplusOutput; 95 | } 96 | 97 | private static void addExitOnFile(String filePath) { 98 | 99 | Writer output = null; 100 | try { 101 | output = new BufferedWriter(new FileWriter(filePath,true)); 102 | output.append(SQLPLUS_EXIT); 103 | output.close(); 104 | } catch (Exception e) { 105 | e.printStackTrace(); 106 | } finally { 107 | if (output != null) { 108 | try { 109 | output.close(); 110 | } catch (IOException e) { 111 | 112 | } 113 | } 114 | } 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/sqlplus/script/runner/test/TestFileUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner.test; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | import org.jenkinsci.plugins.sqlplus.script.runner.FileUtil; 10 | import org.junit.Test; 11 | 12 | import hudson.FilePath; 13 | 14 | public class TestFileUtil { 15 | 16 | private static final String SCRIPT_SQL = "src/test/resources/script.sql"; 17 | private static final String SCRIPT2_SQL = "src/test/resources/script2.sql"; 18 | 19 | static final String WORK_DIR = System.getProperty("user.dir"); 20 | 21 | @Test 22 | public void testExitInScriptFile() throws IOException,InterruptedException { 23 | 24 | 25 | File file = new File(WORK_DIR+File.separator+SCRIPT_SQL); 26 | 27 | boolean hasExit = FileUtil.hasExitCode(new FilePath(file)); 28 | 29 | System.out.println("hasExit = " + hasExit); 30 | 31 | assertTrue(hasExit); 32 | } 33 | 34 | @Test 35 | public void testNoExitInScriptFile() throws IOException,InterruptedException { 36 | 37 | 38 | File file = new File(WORK_DIR+File.separator+SCRIPT2_SQL); 39 | 40 | boolean hasExit = FileUtil.hasExitCode(new FilePath(file)); 41 | 42 | System.out.println("hasNoExit = " + hasExit); 43 | 44 | assertFalse(hasExit); 45 | } 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/sqlplus/script/runner/test/TestSQLPlus.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.sqlplus.script.runner.test; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | import org.jenkinsci.plugins.sqlplus.script.runner.ScriptType; 9 | import org.junit.Ignore; 10 | import org.junit.Test; 11 | 12 | @Ignore 13 | /* 14 | * In order to run this test Oracle SQL*Plus is needed 15 | */ 16 | public class TestSQLPlus { 17 | 18 | private static final String SCRIPT_SQL = "script.sql"; 19 | private static final String ORACLE_PASSWORD = "dimdim"; 20 | private static final String ORACLE_USER = "minhasmoedas"; 21 | static final String ORACLE_HOME = "/oracle/app/oracle/product/12.1.0/dbhome_1/"; 22 | static final String ORACLE_INSTANCE = "ora"; 23 | static final String WORK_DIR = System.getProperty("user.dir"); 24 | 25 | @Test 26 | public void testVersion() throws IOException,InterruptedException { 27 | 28 | String detectedVersion = ExternalProgramUtil.getVersion(WORK_DIR,ORACLE_HOME); 29 | 30 | System.out.println("SQLPlus detected version = " + detectedVersion); 31 | 32 | assertTrue(detectedVersion.contains("SQL*Plus: Release 12.1.0.1.0 Production")); 33 | } 34 | 35 | @Test 36 | public void testUserDefinedScriptFile() throws IOException,InterruptedException { 37 | 38 | ClassLoader classLoader = getClass().getClassLoader(); 39 | File file = new File(classLoader.getResource(SCRIPT_SQL).getFile()); 40 | 41 | String output = ExternalProgramUtil.run(ORACLE_USER,ORACLE_PASSWORD,ORACLE_INSTANCE,file.getCanonicalPath(),WORK_DIR,ORACLE_HOME,ScriptType.userDefined.name()); 42 | 43 | System.out.println("output = " + output); 44 | 45 | assertTrue(output.contains("BANNER")); 46 | } 47 | 48 | @Test 49 | public void testRunningScriptFile() throws IOException,InterruptedException { 50 | 51 | String output = ExternalProgramUtil.run(ORACLE_USER,ORACLE_PASSWORD,ORACLE_INSTANCE,"src/test/resources/script.sql",WORK_DIR,ORACLE_HOME,ScriptType.file.name()); 52 | 53 | System.out.println("output = " + output); 54 | 55 | assertTrue(output.contains("BANNER")); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/resources/script.sql: -------------------------------------------------------------------------------- 1 | select * from v$version; 2 | 3 | exit; 4 | -------------------------------------------------------------------------------- /src/test/resources/script2.sql: -------------------------------------------------------------------------------- 1 | select * from v$version; 2 | -------------------------------------------------------------------------------- /src/test/resources/script3.sql: -------------------------------------------------------------------------------- 1 | select * from dict; 2 | 3 | exit; 4 | --------------------------------------------------------------------------------