├── .gitattributes ├── .mvn ├── maven.config └── extensions.xml ├── src ├── main │ ├── webapp │ │ ├── help-propagateParams_zh_CN.html │ │ ├── help-disableRemoteCatalog_zh_CN.html │ │ ├── help-disableRemoteCatalog_ja.html │ │ ├── help-params_zh_CN.html │ │ ├── help-propagateParams.html │ │ ├── help-disableRemoteCatalog.html │ │ ├── help-params.html │ │ ├── scriptler.css │ │ └── lib │ │ │ └── scriptler.js │ ├── java │ │ └── org │ │ │ └── jenkinsci │ │ │ └── plugins │ │ │ └── scriptler │ │ │ ├── config │ │ │ ├── NamedResource.java │ │ │ ├── Parameter.java │ │ │ ├── ScriptSet.java │ │ │ ├── ScriptlerConfiguration.java │ │ │ └── Script.java │ │ │ ├── share │ │ │ ├── ScriptInfoCatalog.java │ │ │ ├── gh │ │ │ │ ├── CentralScriptJsonCatalog.java │ │ │ │ └── GHCatalog.java │ │ │ ├── CatalogInfo.java │ │ │ └── ScriptInfo.java │ │ │ ├── TransientActionProvider.java │ │ │ ├── NodeNames.java │ │ │ ├── ScriptlerPermissions.java │ │ │ ├── util │ │ │ ├── ByIdSorter.java │ │ │ ├── UIHelper.java │ │ │ ├── ControllerGroovyScript.java │ │ │ ├── GroovyScript.java │ │ │ └── ScriptHelper.java │ │ │ ├── git │ │ │ ├── GitScriptlerRepositorySSHAccess.java │ │ │ └── GitScriptlerRepository.java │ │ │ ├── tokenmacro │ │ │ └── ScriptlerTokenMacro.java │ │ │ ├── SyncUtil.java │ │ │ └── ScriptlerLoadingTasks.java │ └── resources │ │ ├── org │ │ └── jenkinsci │ │ │ └── plugins │ │ │ └── scriptler │ │ │ ├── ScriptlerManagement │ │ │ ├── sidepanel_zh_CN.properties │ │ │ ├── sidepanel.properties │ │ │ ├── show_zh_CN.properties │ │ │ ├── catalog_zh_CN.properties │ │ │ ├── settings_zh_CN.properties │ │ │ ├── index_zh_CN.properties │ │ │ ├── confirm-remove.js │ │ │ ├── edit_zh_CN.properties │ │ │ ├── scriptSettings_zh_CN.properties │ │ │ ├── runScript_zh_CN.properties │ │ │ ├── sidepanel_ja.properties │ │ │ ├── show_ja.properties │ │ │ ├── show.properties │ │ │ ├── index_ja.properties │ │ │ ├── runScript_ja.properties │ │ │ ├── catalog_ja.properties │ │ │ ├── settings_ja.properties │ │ │ ├── edit_ja.properties │ │ │ ├── catalog.properties │ │ │ ├── settings.properties │ │ │ ├── scriptSettings_ja.properties │ │ │ ├── index.properties │ │ │ ├── edit.properties │ │ │ ├── scriptSettings.properties │ │ │ ├── runScript.properties │ │ │ ├── sidepanel.jelly │ │ │ ├── settings.jelly │ │ │ ├── scriptSettings.jelly │ │ │ ├── show.jelly │ │ │ ├── catalog.jelly │ │ │ ├── edit.jelly │ │ │ ├── runScript.jelly │ │ │ └── index.jelly │ │ │ ├── git │ │ │ └── GitScriptlerRepository │ │ │ │ ├── index_zh_CN.properties │ │ │ │ ├── index.properties │ │ │ │ └── index.jelly │ │ │ ├── builder │ │ │ └── ScriptlerBuilder │ │ │ │ ├── help_zh_CN.html │ │ │ │ ├── config_zh_CN.properties │ │ │ │ ├── help.html │ │ │ │ ├── config_ja.properties │ │ │ │ ├── config.properties │ │ │ │ └── config.jelly │ │ │ ├── tokenmacro │ │ │ └── ScriptlerTokenMacro │ │ │ │ └── help.jelly │ │ │ ├── Messages_zh_CN.properties │ │ │ ├── Messages_ja.properties │ │ │ └── Messages.properties │ │ └── index.jelly └── test │ ├── resources │ ├── casc.yaml │ ├── parsing_test.groovy │ ├── scriptler-catalog.xml │ ├── simple2.json │ ├── simple1.json │ ├── JENKINS-13518.json │ └── scriptler.xml │ └── java │ └── org │ └── jenkinsci │ └── plugins │ └── scriptler │ ├── config │ ├── ParameterTest.java │ └── ScriptTest.java │ ├── ScriptlerManagementHelper.java │ ├── tokenmacro │ └── ScriptlerTokenMacroTest.java │ ├── ScriptlerPermissionsTests.java │ ├── util │ ├── ScriptHelperTest.java │ ├── UIHelperTest.java │ └── GroovyScriptTest.java │ ├── ScriptlerManagementTest.java │ └── restapi │ └── ScriptlerRestApiTest.java ├── docs └── images │ ├── screen-capture-1.gif │ ├── screen-capture-10.jpg │ ├── screen-capture-11.jpg │ ├── screen-capture-8.jpg │ ├── screen-capture-9.jpg │ └── scriptler-builder.jpg ├── .gitignore ├── Jenkinsfile ├── .github ├── dependabot.yml └── workflows │ ├── cd.yaml │ └── jenkins-security-scan.yml ├── LICENSE ├── pom.xml ├── README.md └── CHANGELOG.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -Pconsume-incrementals 2 | -Pmight-produce-incrementals 3 | -Dchangelist.format=%d.v%s 4 | -------------------------------------------------------------------------------- /src/main/webapp/help-propagateParams_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 此选项允许将作业参数传递到脚本执行中,这样就不会被迫重复参数。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help-disableRemoteCatalog_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 选中此选项可以禁用远程目录功能(将无法从远程主机导入脚本)。 3 |
4 | -------------------------------------------------------------------------------- /docs/images/screen-capture-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/screen-capture-1.gif -------------------------------------------------------------------------------- /docs/images/screen-capture-10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/screen-capture-10.jpg -------------------------------------------------------------------------------- /docs/images/screen-capture-11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/screen-capture-11.jpg -------------------------------------------------------------------------------- /docs/images/screen-capture-8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/screen-capture-8.jpg -------------------------------------------------------------------------------- /docs/images/screen-capture-9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/screen-capture-9.jpg -------------------------------------------------------------------------------- /docs/images/scriptler-builder.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jenkinsci/scriptler-plugin/HEAD/docs/images/scriptler-builder.jpg -------------------------------------------------------------------------------- /src/main/webapp/help-disableRemoteCatalog_ja.html: -------------------------------------------------------------------------------- 1 |
2 | このオプションをチェックすると、リモートカタログ機能を無効にすることができます(リモートホストからスクリプトをインポートすることができなくなります)。 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help-params_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 定义传递给脚本执行的参数,值可以是常量值,也可以是通过token 宏插件扩展的变量。 3 |
4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /work 3 | /.settings 4 | /.classpath 5 | /.project 6 | /bin 7 | /scriptler (org.jenkins-ci.plugins).iml 8 | /dummy.groovy 9 | /.idea 10 | /scriptler.iml 11 | -------------------------------------------------------------------------------- /src/main/webapp/help-propagateParams.html: -------------------------------------------------------------------------------- 1 |
2 | This option allows to pass the job parameters into the script execution, this way, one is not forced to duplicate params. 3 |
4 | -------------------------------------------------------------------------------- /src/main/webapp/help-disableRemoteCatalog.html: -------------------------------------------------------------------------------- 1 |
2 | Checking this option, will disable the remote catalog feature - you will not be able to import scripts from a remote host anymore. 3 |
4 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/config/NamedResource.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.config; 2 | 3 | public interface NamedResource { 4 | 5 | String getName(); 6 | 7 | String getId(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/sidepanel_zh_CN.properties: -------------------------------------------------------------------------------- 1 | runEditScripts=运行 / 编辑脚本 2 | addNewScript=添加新脚本 3 | remoteScriptCatalogs=远程脚本目录 4 | scriptlerSettings=脚本管理器设置 5 | gitRepo=Git 存储库 6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepository/index_zh_CN.properties: -------------------------------------------------------------------------------- 1 | blurb=\ 2 | 这个 Git 存储库通过 Git 存储库公开了一个 scriptler 目录。\ 3 | 任何人都可以拉取/克隆此存储库,但只有管理员可以推送。 4 | reset=如果出现严重问题,您可以对主分支进行硬重置。 5 | hardReset=硬重置 6 | Log=日志 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/sidepanel.properties: -------------------------------------------------------------------------------- 1 | runEditScripts=Run / Edit Scripts 2 | addNewScript=Add a New Script 3 | remoteScriptCatalogs=Remote Script Catalogs 4 | scriptlerSettings=Scriptler Settings 5 | gitRepo=Git Repo 6 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/show_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=脚本详情 2 | Name=名称 3 | IdDescription=唯一脚本 ID 4 | ParamDefinition=必需参数 5 | Comment=注释 6 | Parameters=参数 7 | ParameterName=名称: 8 | ParameterDefaultValue=默认值: 9 | Script=脚本 10 | -------------------------------------------------------------------------------- /src/main/webapp/help-params.html: -------------------------------------------------------------------------------- 1 |
2 | Define parameters to be passed to the script execution, the value can be a constant value or a variable expanded by the token macro plugin. 3 |
4 | -------------------------------------------------------------------------------- /src/test/resources/casc.yaml: -------------------------------------------------------------------------------- 1 | jenkins: 2 | authorizationStrategy: 3 | projectMatrix: 4 | entries: 5 | - group: 6 | name: authenticated 7 | permissions: 8 | - "Scriptler/Configure" 9 | - "Scriptler/RunScripts" 10 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder/help_zh_CN.html: -------------------------------------------------------------------------------- 1 |
2 | 使用作业执行脚本编写器脚本,这可以自动执行许多管理任务,或为特权用户提供预先准备好的脚本。
3 | 选择要在构建期间执行的脚本。可用的脚本是管理员标记为“允许具有 RunScripts 权限的用户执行”的脚本。 4 |

5 | 参数可以通过作业参数传递,也可以在此构建器配置中创建它们。 6 |

7 |
8 | -------------------------------------------------------------------------------- /src/test/resources/parsing_test.groovy: -------------------------------------------------------------------------------- 1 | /*** BEGIN META { 2 | "name" : "print hello", 3 | "comment" : "some cool comment", 4 | "parameters" : [ 'param1', 'param2' ], 5 | "core": "1.300", 6 | "authors" : [ 7 | { name : "Dude mac" } 8 | ] 9 | } END META**/ 10 | println('hello') 11 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | /* 2 | See the documentation for more options: 3 | https://github.com/jenkins-infra/pipeline-library/ 4 | */ 5 | buildPlugin( 6 | forkCount: '1C', 7 | useContainerAgent: true, 8 | configurations: [ 9 | [platform: 'linux', jdk: 21], 10 | [platform: 'windows', jdk: 17] 11 | ]) 12 | -------------------------------------------------------------------------------- /src/test/resources/scriptler-catalog.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | id 6 | name.groovy 7 | comment 8 | N/A 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/catalog_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=远程脚本目录 2 | intro=目录允许您从共享源服务器导入 Groovy 脚本。\ 3 | 只需点击保存图标,脚本就会被导入到本地脚本目录。根据目录的不同,您也可以共享您的脚本 \ 4 | - 例如向 https://github.com/jenkinsci/jenkins-scripts 发送拉取请求。\ 5 | 继续,也分享一些您的脚本吧 :) 6 | importScript=导入脚本 7 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | Scriptler allows you to store/edit/execute Groovy scripts on any of the 4 | nodes... no need for copy paste Groovy code anymore. Beside 5 | administer your scripts, Scriptler also provides a way to share scripts 6 | between users via hosted script catalogs on the internet. 7 |
8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates 2 | 3 | version: 2 4 | updates: 5 | - package-ecosystem: maven 6 | directory: / 7 | schedule: 8 | interval: monthly 9 | - package-ecosystem: github-actions 10 | directory: / 11 | schedule: 12 | interval: monthly 13 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/config/ParameterTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.config; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class ParameterTest { 7 | @Test 8 | void equalsContract() { 9 | EqualsVerifier.forClass(Parameter.class).usingGetClass().verify(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepository/index.properties: -------------------------------------------------------------------------------- 1 | blurb=\ 2 | This Git repository exposes a directory of scriptler via Git repository. \ 3 | Anyone can pull/clone this repository, but only the administrators can push. 4 | reset=In case of serious problems, this lets you do a hard reset on the master branch. 5 | hardReset=Hard Reset 6 | Log=Log 7 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/settings_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=脚本管理器设置 2 | intro=配置脚本管理器以满足您的需求 3 | scriptlerdirectorytext=脚本管理器配置保存位置: 4 | scriptdirectorytext=脚本保存位置: 5 | disabledtext=远程目录已禁用,您需要先启用才能使用此功能! 6 | Directories=目录: 7 | Disable\ remote\ catalog=禁用远程目录 8 | Allow\ RunScript\ permission=允许运行脚本权限 9 | Allow\ RunScript\ editing=允许运行脚本编辑 10 | Submit=提交 11 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder/config_zh_CN.properties: -------------------------------------------------------------------------------- 1 | RequiredParameters=必需参数: 2 | NoPermission=您没有权限更改脚本管理器步骤,更改将不会应用! 3 | WarnNoScript=未定义脚本。请在此处定义一个 4 | Script=脚本 5 | ViewScript=查看选定的脚本 6 | ParametersDescription=定义脚本参数 7 | Parameters=参数 8 | ParameterName=名称: 9 | ParameterValue=值: 10 | DeleteParameter=删除 11 | AddParameter=添加参数 12 | PropagateParams=将作业参数传播到脚本 13 | -------------------------------------------------------------------------------- /.mvn/extensions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | io.jenkins.tools.incrementals 4 | git-changelist-maven-extension 5 | 1.13 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/config/ScriptTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.config; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class ScriptTest { 7 | @Test 8 | void equalsContract() { 9 | EqualsVerifier.forClass(Script.class) 10 | .usingGetClass() 11 | .withOnlyTheseFields("id") 12 | .verify(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/index_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=脚本管理器 2 | intro=您想要做什么?您可以从这里运行、编辑、删除或创建新脚本。如果您选择执行脚本,您将能够选择要运行脚本的节点。 3 | scriptdirectorytext=脚本保存位置: 4 | fileNotAvailable=此文件在系统中物理不可用。 5 | noScriptsAvailable=当前您没有任何可用的脚本。您可以从远程目录导入脚本或创建自己的脚本。 6 | usableInBuildStep=允许在脚本管理器构建步骤中使用 7 | notUsableInBuildStep=不允许在脚本管理器构建步骤中使用 8 | scriptApproved=脚本已批准 9 | scriptNotYetApproved=脚本尚未批准,建议在使用前要求管理员批准 10 | runScript=运行脚本 11 | editScript=编辑脚本 12 | removeScript=删除脚本 13 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/tokenmacro/ScriptlerTokenMacro/help.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 |
$${SCRIPTLER, scriptId="SCRIPT_ID"}
4 |
5 | Expands to the return value of the Scriptler script. The script must have the "Permission" box checked. If the script attempts to use the build parameter, it must have the "Restriction" box checked, for the execution to be restricted to the built-in node. 6 |
7 |
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/confirm-remove.js: -------------------------------------------------------------------------------- 1 | document.addEventListener("DOMContentLoaded", () => { 2 | const removeScriptButtons = document.querySelectorAll(".scriptler-remove-script-form"); 3 | removeScriptButtons.forEach((button) => 4 | button.addEventListener("click", (e) => { 5 | const name = e.currentTarget.dataset.name; 6 | if (!confirm("Sure you want to delete [" + name + "]?")) { 7 | e.preventDefault(); 8 | } 9 | }), 10 | ); 11 | }); 12 | -------------------------------------------------------------------------------- /src/test/resources/simple2.json: -------------------------------------------------------------------------------- 1 | { 2 | "builderId": "", 3 | "defineParams": { 4 | "parameters": [ 5 | { 6 | "name": "param1", 7 | "value": "value1" 8 | }, 9 | { 10 | "name": "param2", 11 | "value": "value2" 12 | } 13 | ] 14 | }, 15 | "kind": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder$DescriptorImpl", 16 | "scriptlerScriptId": "bulkDeleteBuilds.groovy", 17 | "stapler-class": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder" 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder/help.html: -------------------------------------------------------------------------------- 1 |
2 | Execute a scriptler script with a job, this allows the automation of many administration tasks or to provide prepared scripts for privileged users.
3 | Select the script you want to execute during the build. The scripts available are the ones marked by the admin as 'allow for users with RunScripts permission'. 4 |

5 | The parameters can be passed via job params or by creating these in this builder config. 6 |

7 |
8 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | # Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins 2 | 3 | name: cd 4 | on: 5 | workflow_dispatch: 6 | check_run: 7 | types: 8 | - completed 9 | 10 | permissions: 11 | checks: read 12 | contents: write 13 | 14 | jobs: 15 | maven-cd: 16 | uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yml@v1 17 | secrets: 18 | MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} 19 | MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }} 20 | -------------------------------------------------------------------------------- /src/test/resources/simple1.json: -------------------------------------------------------------------------------- 1 | { 2 | "builderId": "1331321162149_1", 3 | "defineParams": { 4 | "parameters": [ 5 | { 6 | "name": "jobName", 7 | "value": "${JOB}" 8 | }, 9 | { 10 | "name": "buildRange", 11 | "value": "1-10" 12 | } 13 | ] 14 | }, 15 | "kind": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder$DescriptorImpl", 16 | "scriptlerScriptId": "bulkDeleteBuilds.groovy", 17 | "stapler-class": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder" 18 | } 19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/edit_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=编辑脚本 2 | Name=名称 3 | IdDescription=如果更改,脚本将被复制 4 | uploadtext=从本地系统选择要上传的 Groovy 脚本,这将覆盖当前文件。 5 | Permission=允许在构建步骤中使用 6 | PermissionDescription=允许将脚本用作脚本管理器构建步骤 7 | Restriction=限制 8 | RestrictionDescription=脚本始终在内置节点上执行 9 | Comment=注释 10 | ParametersDescription=定义脚本参数 11 | Parameters=参数 12 | ParameterName=名称: 13 | ParameterDefaultValue=默认值: 14 | DeleteParameter=删除 15 | AddParameter=添加参数 16 | Script=脚本 17 | Submit=提交 18 | ScriptNotFound=// 未找到脚本源文件 19 | NotApprovedYet=脚本尚未批准,建议要求管理员批准。 20 | NotApprovedYetButHasRightWarn=脚本尚未批准 21 | NotApprovedYetButHasRightInfo=保存后将自动批准。 22 | -------------------------------------------------------------------------------- /src/main/webapp/scriptler.css: -------------------------------------------------------------------------------- 1 | .scriptler-inline { 2 | display: inline; 3 | } 4 | 5 | .scriptler-inline div { 6 | display: inline; 7 | } 8 | 9 | .scriptler-inline button { 10 | padding: 0; 11 | } 12 | 13 | .scriptler-link-button { 14 | background: none; 15 | border: none; 16 | cursor: pointer; 17 | } 18 | 19 | .scriptler-link-button:focus { 20 | outline: none; 21 | } 22 | 23 | .scriptler-link-button:active { 24 | color:red; 25 | } 26 | 27 | .scriptler-toolbar { 28 | white-space: nowrap; 29 | } 30 | 31 | .scriptler-toolbar .scriptler-icon-slot { 32 | margin-left: 8px; 33 | text-decoration: none; 34 | color: inherit; 35 | } 36 | 37 | .scriptler-icon-slot:visited { 38 | color: inherit; 39 | } 40 | -------------------------------------------------------------------------------- /.github/workflows/jenkins-security-scan.yml: -------------------------------------------------------------------------------- 1 | name: Jenkins Security Scan 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | types: [ opened, synchronize, reopened ] 9 | workflow_dispatch: 10 | 11 | permissions: 12 | security-events: write 13 | contents: read 14 | actions: read 15 | 16 | jobs: 17 | security-scan: 18 | uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2 19 | with: 20 | java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate. 21 | # java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default. 22 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/scriptSettings_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=创建新的 Groovy 脚本 2 | intro=\ 3 | 输入任意 Groovy 脚本 并\ 4 | 保存。稍后您将能够在任何代理上执行它。对故障排除和诊断很有用。\ 5 | 使用 ''println'' 命令查看输出(如果您使用 System.out,\ 6 | 它将输出到服务器的标准输出,这更难看到)。如果您认为您的脚本对其他人也有用,请在 https://github.com/jenkinsci/jenkins-scripts 上分享。 7 | uploadtext=从本地系统选择要上传的 Groovy 脚本(*.groovy)。 8 | UploadEncoding=上传的文件应使用 UTF-8 编码。 9 | Permission=允许在构建步骤中使用 10 | Restriction=限制 11 | RestrictionDescription=脚本始终在内置节点上执行 12 | Example=示例: 13 | Name=名称 14 | Comment=注释 15 | Script=脚本 16 | Submit=提交 17 | Upload\ new\ Script=上传新脚本 18 | Upload=上传 19 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/runScript_zh_CN.properties: -------------------------------------------------------------------------------- 1 | title=运行脚本 2 | intro=请选择您要运行脚本的代理。您也可以根据需要修改脚本,更改不会影响脚本的存储版本!

\ 3 | 您还可以通过 POST 到 URL /scriptler/run/<your-script-id> 运行脚本,可选参数包括 nodescript(替代脚本文本)、contentType 以及为存储脚本定义的参数。 4 | modificationRequiredApproval=由于您缺少 Overall/RunScripts 权限,您的修改将被放入脚本批准队列。您仍然可以按原样运行脚本。 5 | executiononclient=此执行在代理 JVM 中进行... 6 | SelectionNode=选择节点 7 | ParametersDescription=定义脚本参数 8 | Parameters=参数 9 | ParameterName=名称: 10 | ParameterValue=值: 11 | Run=运行 12 | Result=结果 13 | ScriptNotFound=// 未找到脚本源文件 14 | NotApprovedYet=脚本尚未批准,建议要求管理员批准。 15 | NotApprovedYetButHasRightWarn=脚本尚未批准 16 | NotApprovedYetButHasRightInfo=运行后将自动批准。 17 | -------------------------------------------------------------------------------- /src/test/resources/JENKINS-13518.json: -------------------------------------------------------------------------------- 1 | { 2 | "":"", 3 | "builder": { 4 | "builderId": "", 5 | "defineParams": false, 6 | "kind": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder", 7 | "parameters": [ 8 | { 9 | "name": "", 10 | "value": "" 11 | }, 12 | { 13 | "name": "", 14 | "value": "" 15 | } 16 | ], 17 | "scriptlerScriptId": "testOutput.groovy", 18 | "stapler-class": "org.jenkinsci.plugins.scriptler.builder.ScriptlerBuilder" 19 | }, 20 | "core:apply": "", 21 | "description": "", 22 | "displayNameOrNull": "", 23 | "name": "test", 24 | "properties": { 25 | "hudson-model-ParametersDefinitionProperty": {}, 26 | "org-jenkinsci-plugins-envinject-EnvInjectJobProperty": {}, 27 | "stapler-class-bag": "true" 28 | }, 29 | "scm": { 30 | "value": "0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/ScriptlerManagementHelper.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import hudson.ExtensionList; 4 | import hudson.model.FileParameterValue; 5 | import java.io.IOException; 6 | import java.nio.charset.StandardCharsets; 7 | import java.nio.file.Files; 8 | import java.nio.file.Path; 9 | import org.apache.commons.fileupload2.core.FileItem; 10 | 11 | public final class ScriptlerManagementHelper { 12 | 13 | private ScriptlerManagementHelper() {} 14 | 15 | public static void saveScript(String scriptId, String contents, boolean nonAdministerUsing) throws IOException { 16 | final ScriptlerManagement scriptler = ExtensionList.lookupSingleton(ScriptlerManagement.class); 17 | 18 | Path f = Files.createTempFile("script", "-temp.groovy"); 19 | Files.writeString(f, contents, StandardCharsets.UTF_8); 20 | FileItem fi = new FileParameterValue.FileItemImpl2(f.toFile()); 21 | scriptler.saveScript(fi, nonAdministerUsing, scriptId); 22 | Files.delete(f); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/share/ScriptInfoCatalog.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.share; 2 | 3 | import hudson.ExtensionList; 4 | import hudson.ExtensionPoint; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public interface ScriptInfoCatalog extends ExtensionPoint { 9 | 10 | @SuppressWarnings({"rawtypes", "unchecked"}) // unfortunate but necessary given ExtensionList's API 11 | static List> all() { 12 | ExtensionList extensions = ExtensionList.lookup(ScriptInfoCatalog.class); 13 | List> typedExtensions = new ArrayList<>(); 14 | for (ScriptInfoCatalog catalog : extensions) { 15 | typedExtensions.add(catalog); 16 | } 17 | return typedExtensions; 18 | } 19 | 20 | T getEntryById(String id); 21 | 22 | CatalogInfo getInfo(); 23 | 24 | List getEntries(); 25 | 26 | String getScriptSource(T scriptInfo); 27 | 28 | String getDisplayName(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/TransientActionProvider.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import hudson.Extension; 5 | import hudson.model.Action; 6 | import hudson.model.Job; 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | import jenkins.model.TransientActionFactory; 10 | 11 | @Extension 12 | @SuppressWarnings("rawtypes") 13 | public class TransientActionProvider extends TransientActionFactory { 14 | @Override 15 | public Class type() { 16 | return Job.class; 17 | } 18 | 19 | @NonNull 20 | @Override 21 | public Collection createFor(@NonNull Job target) { 22 | return Collections.singleton(new ScriptlerManagement() { 23 | @Override 24 | public String getIconFileName() { 25 | return null; 26 | } 27 | 28 | @Override 29 | public String getDisplayName() { 30 | return null; 31 | } 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2016 Dominik Bartholdi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject 11 | to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 20 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 21 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/tokenmacro/ScriptlerTokenMacroTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.tokenmacro; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | 5 | import hudson.model.FreeStyleBuild; 6 | import hudson.model.FreeStyleProject; 7 | import hudson.util.StreamTaskListener; 8 | import org.jenkinsci.plugins.scriptler.ScriptlerManagementHelper; 9 | import org.jenkinsci.plugins.tokenmacro.TokenMacro; 10 | import org.junit.jupiter.api.Test; 11 | import org.jvnet.hudson.test.JenkinsRule; 12 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins; 13 | 14 | @WithJenkins 15 | class ScriptlerTokenMacroTest { 16 | 17 | @Test 18 | void testExecutesScript(JenkinsRule j) throws Exception { 19 | ScriptlerManagementHelper.saveScript("dummy.groovy", "return \"hello world ${build.number}\"", true); 20 | 21 | FreeStyleProject p = j.createFreeStyleProject("foo"); 22 | FreeStyleBuild b = p.scheduleBuild2(0).get(); 23 | 24 | final StreamTaskListener listener = StreamTaskListener.fromStdout(); 25 | 26 | assertEquals("hello world 1", TokenMacro.expand(b, listener, "${SCRIPTLER,scriptId=\"dummy.groovy\"}")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/Messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | display_name=脚本管理器 2 | description=在任何代理或内置节点上存储/编辑/运行脚本。 3 | scriptdirectorytitle=脚本存储位置: 4 | not_groovy_script=这不是一个 Groovy 脚本:{0} 5 | script_loaded_from_directory=此脚本在文件系统中被发现,请描述它! 6 | uploadtext=从本地系统选择要上传的 Groovy 脚本。 7 | node_not_found=节点 [{0}] 未找到! 8 | node_not_online=选定的节点 [{0}] 未在线,因此无法执行脚本!请选择另一个节点或在重试前启动它。 9 | agent_no_channel=代理没有通道 10 | download_failed=从目录 [{1}] 导入脚本 [{0}] 失败。 11 | builder_name=脚本管理器脚本 12 | scriptNotFound=找不到 ID 为 [{0}] 的脚本 13 | scriptNotDefined=脚本管理器未定义脚本,请修复您的配置! 14 | scriptNotUsableInBuildStep=脚本 [{0}] 无法在构建步骤中使用,请检查您的配置。 15 | scriptNotApprovedYet=脚本 [{0}] 尚未批准,请考虑要求管理员批准它。 16 | scriptExecutionFailed=脚本 [{0}] 执行失败 17 | parameterExtractionFailed=从请求中读取参数失败 18 | scriptSourceNotFound=无法加载脚本 [{0}] 的源代码 19 | skipParameter=跳过参数 [{0}],此名称为内部使用,请重命名! 20 | resultPrefix=结果: 21 | no_parameters_defined=此作业未定义任何参数。 22 | tokenmacro_AdminScriptOnly=脚本 [{0}] 存在,但标记为仅供管理员使用,因此不允许在令牌宏中使用。 23 | tokenmacro_ScriptDoesNotExist=找不到 ID 为 [{0}] 的脚本。 24 | permissons_title=脚本管理器 25 | permissons_configure_description=允许配置脚本管理器脚本,允许细粒度调整而不是给每个人 Overall/RunScripts 权限 26 | permissons_runScript_description=允许执行脚本管理器脚本以及插入/修改脚本管理器构建步骤,允许细粒度调整而不是给每个人 Overall/RunScripts 权限 27 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/ScriptlerPermissionsTests.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertTrue; 4 | 5 | import hudson.security.SecurityRealm; 6 | import io.jenkins.plugins.casc.misc.ConfiguredWithCode; 7 | import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; 8 | import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode; 9 | import org.junit.jupiter.api.Test; 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 11 | import org.springframework.security.core.Authentication; 12 | 13 | @WithJenkinsConfiguredWithCode 14 | class ScriptlerPermissionsTests { 15 | @ConfiguredWithCode("/casc.yaml") 16 | @Test 17 | void permissionsAreAvailableOnStartup(JenkinsConfiguredWithCodeRule rule) throws Exception { 18 | SecurityRealm realm = rule.createDummySecurityRealm(); 19 | rule.jenkins.setSecurityRealm(realm); 20 | 21 | UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken("user", "user"); 22 | Authentication a = realm.getSecurityComponents().manager2.authenticate(authRequest); 23 | assertTrue(rule.jenkins.hasPermission2(a, ScriptlerPermissions.CONFIGURE)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/util/ScriptHelperTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.util; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertFalse; 5 | import static org.junit.jupiter.api.Assertions.assertNotNull; 6 | 7 | import java.nio.charset.StandardCharsets; 8 | import java.nio.file.Files; 9 | import java.nio.file.Paths; 10 | import org.jenkinsci.plugins.scriptler.share.ScriptInfo; 11 | import org.junit.jupiter.api.Test; 12 | 13 | class ScriptHelperTest { 14 | 15 | @Test 16 | void testGetJson() throws Exception { 17 | final String content = 18 | Files.readString(Paths.get("src/test/resources/parsing_test.groovy"), StandardCharsets.UTF_8); 19 | assertFalse(content.isBlank(), "no content from file"); 20 | 21 | final ScriptInfo info = ScriptHelper.extractScriptInfo(content); 22 | assertNotNull(info, "ScriptInfo is null"); 23 | assertEquals("1.300", info.getCore()); 24 | assertEquals("print hello", info.getName()); 25 | assertEquals("some cool comment", info.getComment()); 26 | assertEquals("Dude mac", info.getAuthors().get(0).getName()); 27 | assertEquals("param1", info.getParameters().get(0)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/NodeNames.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public final class NodeNames { 9 | public static final String BUILT_IN = "(built-in)"; 10 | public static final String ALL = "(all)"; 11 | public static final String ALL_AGENTS = "(all agents)"; 12 | private static final Map DEPRECATED_ALIASES; 13 | 14 | static { 15 | Map> deprecatedNames = 16 | Map.of(BUILT_IN, List.of("(master)", "(controller)"), ALL_AGENTS, List.of("(all slaves)")); 17 | 18 | Map aliases = new HashMap<>(); 19 | deprecatedNames.forEach( 20 | (newName, oldNames) -> oldNames.forEach(oldName -> aliases.put(normalizeName(oldName), newName))); 21 | 22 | DEPRECATED_ALIASES = Map.copyOf(aliases); 23 | } 24 | 25 | @NonNull 26 | private static String normalizeName(@NonNull String name) { 27 | return name.toLowerCase(); 28 | } 29 | 30 | @NonNull 31 | public static String normalizeNodeName(@NonNull String nodeName) { 32 | return DEPRECATED_ALIASES.getOrDefault(normalizeName(nodeName), nodeName); 33 | } 34 | 35 | private NodeNames() {} 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/sidepanel_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | runEditScripts=スクリプトの実行 / 編集 24 | addNewScript=スクリプトの追加 25 | remoteScriptCatalogs=リモートスクリプトカタログ 26 | scriptlerSettings=Scriptlerの設定 27 | gitRepo=Git リポジトリ 28 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/show_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2012, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=スクリプトの詳細 23 | Name=名前 24 | IdDescription=スクリプトのID 25 | ParamDefinition=必須パラメータ 26 | Comment=コメント 27 | Parameters=パラメータ 28 | ParameterName=名前: 29 | ParameterDefaultValue=デフォルト値: 30 | Script=スクリプト 31 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/show.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2012, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=Script Details 23 | Name=Name 24 | IdDescription=unique script id 25 | ParamDefinition=Required parameters 26 | Comment=Comment 27 | Parameters=Parameters 28 | ParameterName=Name: 29 | ParameterDefaultValue=Default: 30 | Script=Script 31 | -------------------------------------------------------------------------------- /src/test/resources/scriptler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 10 | 15 | 20 | 25 | 26 | 27 | 28 | default 29 | https://raw2.github.com/christ66/scriptler-plugin/master/src/test/resources/scriptler-catalog.xml 30 | https://raw2.github.com/christ66/scriptler-plugin/master/src/test/resources{0} 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/index_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Scriptler 24 | intro=Scriptlerでは、スクリプトの作成/編集/削除/実行を行えます。また、スクリプトを実行する際、どのノードで実行するかを選択することができます。 25 | scriptdirectorytext=スクリプトが保存されているパス: 26 | fileNotAvailable=ファイルが存在しません 27 | noScriptsAvailable=実行出来るスクリプトが存在しません。リモートカタログからインポートするか、スクリプトを作成することができます。 28 | freeForRunSciptPermission=''RunScripts''権限があるユーザに許可されています -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/runScript_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=スクリプトの実行 24 | intro=スクリプトを実行したいスレーブを選択してください。必要に応じてスクリプトを編集することができます。編集した結果は、保存されているスクリプトには反映されません。 25 | executiononclient=下記で選択したスレーブのJVM上で実行されます 26 | SelectionNode=ノードを選択 27 | ParametersDescription=スクリプトのパラメータを定義 28 | Parameters=パラメータ 29 | ParameterName=名前: 30 | ParameterValue=値: 31 | Run=実行 32 | Result=結果 33 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder/config_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2012, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | RequiredParameters=必須パラメータ: 24 | NoPermission = 権限がないので、実行されるスクリプトを変更できません。 25 | WarnNoScript = スクリプトが定義されていません。Scriptlerで定義してください。 26 | Script=スクリプト 27 | ViewScript=選択されたスクリプトを参照する 28 | ParametersDescription=スクリプトのパラメータを定義 29 | Parameters=パラメータ 30 | ParameterName=名前: 31 | ParameterValue=値: 32 | DeleteParameter=削除 33 | AddParameter=パラメータの追加 34 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/catalog_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=リモートスクリプトカタログ 24 | intro=カタログを通じて、共有サーバからGroovyスクリプトをインポートすることができます。\ 25 | 保存アイコンをクリックすると、スクリプトがローカルディレクトリにインポートされます。\ 26 | カタログに応じて、あなたのスクリプトを共有することもできます。\ 27 | https://github.com/jenkinsci/jenkins-scripts にプルリクエストを送るか、\ 28 | scriptlerweb にアップロードしてください。 -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/settings_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Scriptlerの設定 24 | intro=必要に応じて、Scriptlerを設定します 25 | scriptlerdirectorytext=Scriptlerの設定が保存されているパス: 26 | scriptdirectorytext=スクリプトが保存されているパス: 27 | disabledtext=リモートカタログは無効になっています。この機能を使用するには最初に有効にする必要があります。 28 | Directories=ディレクトリ: 29 | Disable\ remote\ catalog=リモートカタログの無効化 30 | Allow\ RunScript\ permission=RunScriptユーザによる実行の許可 31 | Allow\ RunScript\ editing=RunScriptユーザによる編集の許可 32 | Submit=保存 33 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/edit_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=スクリプトの編集 23 | Name=名前 24 | IdDescription=変更した場合、スクリプトがコピーされます 25 | uploadtext=Groovyスクリプトをローカルシステムから選択してください。現在のファイルに上書きされます。 26 | Permission = 権限 27 | PermissionDescription = ''RunScripts''権限があるユーザに、スクリプトの実行を許可するか 28 | Comment=コメント 29 | ParametersDescription=スクリプトのパラメータを定義 30 | Parameters=パラメータ 31 | ParameterName=名前: 32 | ParameterDefaultValue=デフォルト値: 33 | DeleteParameter=削除 34 | AddParameter=パラメータの追加 35 | Script=スクリプト 36 | Submit=保存 37 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/ScriptlerPermissions.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 4 | import hudson.init.InitMilestone; 5 | import hudson.init.Initializer; 6 | import hudson.security.Permission; 7 | import hudson.security.PermissionGroup; 8 | import hudson.security.PermissionScope; 9 | import jenkins.model.Jenkins; 10 | 11 | public final class ScriptlerPermissions { 12 | public static final PermissionGroup SCRIPTLER_PERMISSIONS = 13 | new PermissionGroup(ScriptlerManagement.class, Messages._permissons_title()); 14 | 15 | public static final Permission CONFIGURE = new Permission( 16 | SCRIPTLER_PERMISSIONS, 17 | "Configure", 18 | Messages._permissons_configure_description(), 19 | Jenkins.ADMINISTER, 20 | PermissionScope.JENKINS); 21 | 22 | public static final Permission RUN_SCRIPTS = new Permission( 23 | SCRIPTLER_PERMISSIONS, 24 | "RunScripts", 25 | Messages._permissons_runScript_description(), 26 | CONFIGURE, 27 | PermissionScope.JENKINS); 28 | 29 | public static final Permission BYPASS_APPROVAL = Jenkins.ADMINISTER; 30 | 31 | private ScriptlerPermissions() {} 32 | 33 | @SuppressFBWarnings( 34 | value = "RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT", 35 | justification = "getEnabled return value discarded") 36 | @Initializer(after = InitMilestone.PLUGINS_STARTED, before = InitMilestone.EXTENSIONS_AUGMENTED) 37 | public static void ensurePermissionsRegistered() { 38 | CONFIGURE.getEnabled(); 39 | RUN_SCRIPTS.getEnabled(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/util/ByIdSorter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright (c) 2010, Dominik Bartholdi 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package org.jenkinsci.plugins.scriptler.util; 25 | 26 | import java.io.Serializable; 27 | import java.util.Comparator; 28 | import org.jenkinsci.plugins.scriptler.config.NamedResource; 29 | 30 | /** 31 | * @author imod 32 | * 33 | */ 34 | public class ByIdSorter implements Comparator, Serializable { 35 | public int compare(NamedResource o1, NamedResource o2) { 36 | return o1.getId().compareTo(o2.getId()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/catalog.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Remote Script Catalogs 24 | intro=The catalog allows you to import groovy scripts from a shared source server. \ 25 | Just click the save icon and the script will be imported to your local script directory. Depending on the catalog, you can share your scripts too \ 26 | - e.g. send pull requests to https://github.com/jenkinsci/jenkins-scripts. \ 27 | Go on, share some of your scripts too :) 28 | importScript=Import script 29 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepository/index.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |

Accessing Scriptler scripts

8 |

${%blurb}

9 |
10 | git clone ${it.httpCloneUrl}
11 | git clone ${it.sshCloneUrl}
12 |             
13 | 14 |

15 | ${%reset} 16 | 17 | 18 | 19 |

20 |
21 | 22 |
23 |

${%Log}

24 | 25 |

26 | commit ${log.name()}
27 | Author: ${log.author().name} &lt;${log.author().emailAddress}&gt;
28 | Committer: ${log.committer().name} &lt;${log.committer().emailAddress}&gt;
29 | Date: ${log.commitTime()}
30 | ${log.msg()} 31 |

32 |
33 |
34 |
35 |
36 |
37 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/builder/ScriptlerBuilder/config.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2012, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | RequiredParameters=Required Parameters: 24 | NoPermission = You don''t have permission to change Scriptler steps, changes will not be applied! 25 | WarnNoScript = No scripts are defined. Please define one at 26 | Script=Script 27 | ViewScript=view selected script 28 | ParametersDescription=Define script parameters 29 | Parameters=Parameters 30 | ParameterName=Name: 31 | ParameterValue=Value: 32 | DeleteParameter=Delete 33 | AddParameter=Add Parameter 34 | PropagateParams=Propagate Job params to script 35 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/settings.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Scriptler Settings 24 | intro=Configure the Scriptler to fit your requirements 25 | scriptlerdirectorytext=The Scriptler configurations are saved at: 26 | scriptdirectorytext=The scripts are saved at: 27 | disabledtext=Remote catalogs are disabled, you have to enable first to use this feature! 28 | Directories=Directories: 29 | Disable\ remote\ catalog=Disable remote catalog 30 | Allow\ RunScript\ permission=Allow RunScript permission 31 | Allow\ RunScript\ editing=Allow RunScript editing 32 | Submit=Submit 33 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/share/gh/CentralScriptJsonCatalog.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.share.gh; 2 | 3 | import hudson.Extension; 4 | import hudson.ExtensionList; 5 | import hudson.model.DownloadService.Downloadable; 6 | import java.io.IOException; 7 | import java.util.Collection; 8 | import java.util.List; 9 | import net.sf.json.JSONArray; 10 | import net.sf.json.JSONObject; 11 | import net.sf.json.JsonConfig; 12 | import org.jenkinsci.plugins.scriptler.share.ScriptInfo; 13 | 14 | /** 15 | * Gets the GitHub catalog from jenkins.io/org.jenkinsci.plugins.scriptler.CentralScriptJsonCatalog.json. 16 | * This catalog is updated by a background crawler on the Jenkins infrastructure site. 17 | * 18 | * @author Dominik Bartholdi (imod) 19 | */ 20 | @Extension 21 | public class CentralScriptJsonCatalog extends Downloadable { 22 | 23 | public static final String ID = "org.jenkinsci.plugins.scriptler.CentralScriptJsonCatalog"; 24 | 25 | public CentralScriptJsonCatalog() { 26 | super(ID); 27 | } 28 | 29 | @SuppressWarnings("unchecked") 30 | public Collection getScripts() throws IOException { 31 | JSONObject d = getData(); 32 | if (d == null) { 33 | return List.of(); 34 | } 35 | JsonConfig config = new JsonConfig(); 36 | config.setCollectionType(List.class); 37 | config.setRootClass(ScriptInfo.class); 38 | return JSONArray.toCollection(d.getJSONArray("list"), config); 39 | } 40 | 41 | public static CentralScriptJsonCatalog getCatalog() { 42 | return ExtensionList.lookupSingleton(CentralScriptJsonCatalog.class); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/util/UIHelper.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.util; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.util.List; 5 | import java.util.Optional; 6 | import java.util.function.Function; 7 | import net.sf.json.JSONObject; 8 | import org.jenkinsci.plugins.scriptler.config.Parameter; 9 | 10 | public final class UIHelper { 11 | 12 | private UIHelper() {} 13 | 14 | /** 15 | * Extracts the parameters from the given request 16 | * 17 | * @param json 18 | * the request potentially containing parameters 19 | * @return parameters - might be an empty array, but never null. 20 | */ 21 | @NonNull 22 | public static List extractParameters(JSONObject json) { 23 | final JSONObject defineParams = json.optJSONObject("defineParams"); 24 | if (defineParams == null || defineParams.isNullObject()) { 25 | // no parameters defined 26 | return List.of(); 27 | } 28 | 29 | final List argsArray = Optional.>ofNullable(defineParams.optJSONArray("parameters")) 30 | .orElseGet(() -> { 31 | JSONObject argsObj = defineParams.optJSONObject("parameters"); 32 | if (argsObj == null) { 33 | return List.of(); 34 | } 35 | return List.of(argsObj); 36 | }); 37 | return mapJsonArray(argsArray, Parameter::new); 38 | } 39 | 40 | private static List mapJsonArray(List array, Function mapper) { 41 | return array.stream() 42 | .filter(JSONObject.class::isInstance) 43 | .map(JSONObject.class::cast) 44 | .map(mapper) 45 | .toList(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/config/Parameter.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.config; 2 | 3 | import java.io.Serial; 4 | import java.io.Serializable; 5 | import java.util.*; 6 | import net.sf.json.JSONObject; 7 | import org.kohsuke.stapler.DataBoundConstructor; 8 | 9 | public class Parameter implements Serializable { 10 | @Serial 11 | private static final long serialVersionUID = 1L; 12 | 13 | private static final String KEY_NAME = "name"; 14 | private static final String KEY_VALUE = "value"; 15 | private static final Set PROPERTY_NAMES = Set.of(KEY_NAME, KEY_VALUE); 16 | 17 | private final String name; 18 | private final String value; 19 | 20 | public Parameter(JSONObject object) { 21 | Set keys = object.keySet(); 22 | if (!PROPERTY_NAMES.equals(keys)) { 23 | throw new IllegalArgumentException("Provided JSONObject does not appear to be a Parameter"); 24 | } 25 | name = object.getString(KEY_NAME); 26 | value = object.getString(KEY_VALUE); 27 | } 28 | 29 | @DataBoundConstructor 30 | public Parameter(String name, String value) { 31 | this.name = name; 32 | this.value = value; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public String getValue() { 40 | return value; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return name + "=" + value; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | 53 | Parameter parameter = (Parameter) o; 54 | return Objects.equals(name, parameter.name) && Objects.equals(value, parameter.value); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return Objects.hash(name, value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/git/GitScriptlerRepositorySSHAccess.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package org.jenkinsci.plugins.scriptler.git; 5 | 6 | import hudson.Extension; 7 | import hudson.ExtensionList; 8 | import java.io.IOException; 9 | import org.eclipse.jgit.transport.ReceivePack; 10 | import org.eclipse.jgit.transport.UploadPack; 11 | import org.jenkinsci.plugins.gitserver.RepositoryResolver; 12 | 13 | /** 14 | * Exposes this repository over SSH. 15 | * 16 | * @author Dominik Bartholdi (imod) 17 | * 18 | */ 19 | @Extension 20 | public class GitScriptlerRepositorySSHAccess extends RepositoryResolver { 21 | 22 | /** 23 | * @see org.jenkinsci.plugins.gitserver.RepositoryResolver#createReceivePack(java.lang.String) 24 | */ 25 | @Override 26 | public ReceivePack createReceivePack(String fullRepositoryName) throws IOException { 27 | if (isMine(fullRepositoryName)) { 28 | GitScriptlerRepository repo = ExtensionList.lookupSingleton(GitScriptlerRepository.class); 29 | return repo.createReceivePack(repo.openRepository()); 30 | } 31 | return null; 32 | } 33 | 34 | /** 35 | * @see org.jenkinsci.plugins.gitserver.RepositoryResolver#createUploadPack(java.lang.String) 36 | */ 37 | @Override 38 | public UploadPack createUploadPack(String fullRepositoryName) throws IOException { 39 | if (isMine(fullRepositoryName)) { 40 | GitScriptlerRepository repo = ExtensionList.lookupSingleton(GitScriptlerRepository.class); 41 | return new UploadPack(repo.openRepository()); 42 | } 43 | return null; 44 | } 45 | 46 | private boolean isMine(String name) { 47 | // Depending on the Git URL the client uses, we may or may not get leading '/'. 48 | // For example, server:userContent.git vs ssh://server/scriptler.git 49 | if (name.startsWith("/")) name = name.substring(1); 50 | return name.equals(GitScriptlerRepository.REPOID); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/scriptSettings_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=スクリプトの作成 23 | intro=\ 24 | 任意のGroovyスクリプトを入力して保存します。\ 25 | 保存すると、各ノード上でスクリプトを実行できるようになります。\ 26 | トラブルシューティングや診断に便利です。\ 27 | 出力を見るには'println'コマンドを使用します(System.outを使用するとサーバーの標準出力に出力されますが、見にくいです)。\ 28 | あなたのスクリプトが便利なものならば、ぜひ \ 29 | https://github.com/jenkinsci/jenkins-scripts や \ 30 | scriptler web で共有してください。 31 | uploadtext=アップロードするGroovyスクリプトを選択してください 32 | Permission = ''RunScripts''権限があるユーザに、スクリプトの実行を許可するか 33 | Example=例: 34 | Name=名前 35 | Comment=コメント 36 | Script=スクリプト 37 | Submit=保存 38 | Upload\ new\ Script=スクリプトのアップロード 39 | Upload=アップロード 40 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/ScriptlerManagementTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertThrows; 5 | 6 | import edu.umd.cs.findbugs.annotations.NonNull; 7 | import hudson.markup.MarkupFormatter; 8 | import hudson.markup.RawHtmlMarkupFormatter; 9 | import java.io.IOException; 10 | import java.io.Writer; 11 | import org.junit.jupiter.api.Test; 12 | import org.jvnet.hudson.test.JenkinsRule; 13 | import org.jvnet.hudson.test.junit.jupiter.WithJenkins; 14 | 15 | @WithJenkins 16 | class ScriptlerManagementTest { 17 | 18 | private static final String DANGEROUS_TEXT = ""; 19 | 20 | @Test 21 | void markupFormatter(JenkinsRule r) throws IOException { 22 | ScriptlerManagement management = new ScriptlerManagement(); 23 | 24 | // save text 25 | String text = management.getMarkupFormatter().translate("Save text"); 26 | assertEquals("Save text", text); 27 | 28 | // dangerous text with global formatter 29 | text = management.getMarkupFormatter().translate(DANGEROUS_TEXT); 30 | assertEquals("<script>alert('PWND!')</script>", text); 31 | 32 | // dangerous text with OWASP formatter 33 | r.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE); 34 | text = management.getMarkupFormatter().translate(DANGEROUS_TEXT); 35 | assertEquals("", text); 36 | 37 | // save text with broken formatter 38 | MarkupFormatter formatter = new MarkupFormatter() { 39 | @Override 40 | public void translate(String markup, @NonNull Writer output) throws IOException { 41 | throw new IOException("Oh no!"); 42 | } 43 | }; 44 | r.jenkins.setMarkupFormatter(formatter); 45 | assertThrows(IOException.class, () -> management.getMarkupFormatter().translate(DANGEROUS_TEXT)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/share/CatalogInfo.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.share; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import java.text.MessageFormat; 5 | 6 | public class CatalogInfo { 7 | 8 | @NonNull 9 | public final String name; 10 | 11 | @NonNull 12 | public final String catalogLocation; 13 | 14 | @NonNull 15 | public final String scriptDownloadUrl; 16 | 17 | @NonNull 18 | public final String scriptDetailUrl; 19 | 20 | /** 21 | * Holds the informations used to connect to a catalog location 22 | * 23 | * @param name 24 | * symbolic name of the catalog, must be unique. 25 | * @param catLocation 26 | * where to download the catalog file from (including file name, e.g. http://myserver.com/scriptler/my-scriptler-catalog.xml ) 27 | * @param scriptDownloadUrl 28 | * the url to download a script by its name. Use {0} to mark the position for the file name in the url (e.g. http://myserver.com/scriptler/{0}) 29 | */ 30 | public CatalogInfo( 31 | @NonNull String name, 32 | @NonNull String catLocation, 33 | @NonNull String scriptDetailUrl, 34 | @NonNull String scriptDownloadUrl) { 35 | this.name = name; 36 | this.catalogLocation = catLocation; 37 | this.scriptDownloadUrl = scriptDownloadUrl; 38 | this.scriptDetailUrl = scriptDetailUrl; 39 | } 40 | 41 | public String getReplacedDownloadUrl(String scriptName, String id) { 42 | if (scriptDownloadUrl.isEmpty()) { 43 | return null; 44 | } 45 | return MessageFormat.format(scriptDownloadUrl.trim(), scriptName, id); 46 | } 47 | 48 | public String getReplacedDetailUrl(String scriptName, String id) { 49 | if (scriptDetailUrl.isEmpty()) { 50 | return null; 51 | } 52 | return MessageFormat.format(scriptDetailUrl.trim(), scriptName, id); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/jenkinsci/plugins/scriptler/util/UIHelperTest.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.util; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertNotNull; 5 | import static org.junit.jupiter.params.provider.Arguments.arguments; 6 | 7 | import java.io.IOException; 8 | import java.net.URISyntaxException; 9 | import java.net.URL; 10 | import java.nio.charset.StandardCharsets; 11 | import java.nio.file.Files; 12 | import java.nio.file.Path; 13 | import java.nio.file.Paths; 14 | import java.util.Collection; 15 | import java.util.Objects; 16 | import java.util.stream.Stream; 17 | import net.sf.json.JSONObject; 18 | import net.sf.json.JSONSerializer; 19 | import org.jenkinsci.plugins.scriptler.config.Parameter; 20 | import org.junit.jupiter.params.ParameterizedTest; 21 | import org.junit.jupiter.params.provider.Arguments; 22 | import org.junit.jupiter.params.provider.MethodSource; 23 | 24 | class UIHelperTest { 25 | static Stream filesAndExpectedParameters() { 26 | return Stream.of(arguments("simple1", 2), arguments("simple2", 2), arguments("JENKINS-13518", 0)); 27 | } 28 | 29 | @ParameterizedTest 30 | @MethodSource("filesAndExpectedParameters") 31 | void testExtractParameters(String fileName, int expectedParameters) throws Exception { 32 | JSONObject json = getJsonFromFile("/" + fileName + ".json"); 33 | final Collection extractParameters = UIHelper.extractParameters(json); 34 | assertNotNull(extractParameters, "no parameters extracted"); 35 | assertEquals(expectedParameters, extractParameters.size(), "not all params extracted"); 36 | } 37 | 38 | private JSONObject getJsonFromFile(String resource) throws IOException, URISyntaxException { 39 | URL url = UIHelperTest.class.getResource(resource); 40 | final Path path = Paths.get(Objects.requireNonNull(url).toURI()); 41 | String jsonTxt = Files.readString(path, StandardCharsets.UTF_8); 42 | return (JSONObject) JSONSerializer.toJSON(jsonTxt); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/index.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Scriptler 24 | intro=What do you want to do? You''re able to run, edit, delete or create new scripts from here. If you select a script to be executed, you''ll be able to select the node where you would like it to run. 25 | scriptdirectorytext=The scripts are saved at: 26 | fileNotAvailable=This file is physically not available on the system. 27 | noScriptsAvailable=Currently you do not have any scripts available. You can import scripts from a remote catalog or create your own. 28 | usableInBuildStep=Allowed to be used in Scriptler build step 29 | notUsableInBuildStep=Not allowed to be used in Scriptler build step 30 | scriptApproved=Script approved 31 | scriptNotYetApproved=Script not yet approved, consider asking an administrator to approve it before use 32 | runScript=Run script 33 | editScript=Edit script 34 | removeScript=Remove Script 35 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/Messages_ja.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | display_name=Scriptler 24 | description=スレーブやマスター上で実行されるスクリプトを管理(保存/編集/実行)します。 25 | scriptdirectorytitle=スクリプトが保存されているパス: 26 | not_groovy_script=Groovyスクリプトではありません:{0} 27 | script_loaded_from_directory=このスクリプトがファイルシステム上で見つかりました。説明を記述してください。 28 | uploadtext=アップロードするGroovyスクリプトを選択してください 29 | node_not_found=ノード [{0}] が見つかりません 30 | node_not_online=選択されたノード [{0}] がオンラインではありません。よって、スクリプトが実行できません。他のノードを選択するか再実行前にノードを開始してください。 31 | download_failed=カタログ [{1}] からのスクリプト [{0}] のインポートが失敗しました 32 | builder_name=Scriptlerスクリプトの実行 33 | scriptNotFound = id [{0}] のスクリプトが見つかりません 34 | scriptNotDefined = Scriptlerによって定義されたスクリプトがありません。設定を見直してください。 35 | scriptExecutionFailed = スクリプト [{0}] の実行が失敗しました 36 | parameterExtractionFailed = リクエストのパラメータ読み込みに失敗しました 37 | scriptSourceNotFound = スクリプト [{0}] のソースを読み込めませんでした 38 | skipParameter = [{0}] は内部で使用されているため、スキップされました。名前を変更してください。 39 | resultPrefix = Result: 40 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/edit.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=Edit Script 23 | Name=Name 24 | IdDescription=if changed, the script gets copied 25 | uploadtext=Select a Groovy script from your local system to be uploaded this will overwrite the current file. 26 | Permission = Allow usage in build step 27 | PermissionDescription = Allow usage of the script as a Scriptler build step 28 | Restriction = Restriction 29 | RestrictionDescription = Script is always executed on the built-in node 30 | Comment=Comment 31 | ParametersDescription=Define script parameters 32 | Parameters=Parameters 33 | ParameterName=Name: 34 | ParameterDefaultValue=Default: 35 | DeleteParameter=Delete 36 | AddParameter=Add Parameter 37 | Script=Script 38 | Submit=Submit 39 | ScriptNotFound=// Script source file was not found 40 | NotApprovedYet=Script not yet approved, consider asking your administrator to approve it. 41 | NotApprovedYetButHasRightWarn=Script not yet approved 42 | NotApprovedYetButHasRightInfo=By saving it you will automatically approve it. 43 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/util/ControllerGroovyScript.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.util; 2 | 3 | import edu.umd.cs.findbugs.annotations.NonNull; 4 | import groovy.lang.GroovyShell; 5 | import hudson.Launcher; 6 | import hudson.model.AbstractBuild; 7 | import hudson.model.TaskListener; 8 | import java.io.Serial; 9 | import java.util.Collection; 10 | import jenkins.model.Jenkins; 11 | import org.jenkinsci.plugins.scriptler.config.Parameter; 12 | 13 | public class ControllerGroovyScript extends GroovyScript { 14 | @Serial 15 | private static final long serialVersionUID = 1L; 16 | 17 | private final transient AbstractBuild build; 18 | private final transient Launcher launcher; 19 | 20 | /** 21 | * This constructor can only be used when the script is executed on the built-in node, because launcher and build 22 | * can not be transferred to an agent and therefore the execution will fail 23 | * @param script the script to be executed 24 | * @param parameters the parameters to be passed to the script 25 | * @param failWithException should the job fail with an exception 26 | * @param listener access to logging via listener 27 | * @param launcher the launcher 28 | * @param build the current build 29 | */ 30 | public ControllerGroovyScript( 31 | String script, 32 | @NonNull Collection parameters, 33 | boolean failWithException, 34 | TaskListener listener, 35 | Launcher launcher, 36 | AbstractBuild build) { 37 | super(script, parameters, failWithException, listener); 38 | this.build = build; 39 | this.launcher = launcher; 40 | } 41 | 42 | @Override 43 | public ClassLoader getClassLoader() { 44 | return Jenkins.get().getPluginManager().uberClassLoader; 45 | } 46 | 47 | @Override 48 | protected void setShellVariables(@NonNull GroovyShell shell) { 49 | super.setShellVariables(shell); 50 | if (build != null) { 51 | shell.setVariable("build", build); 52 | } 53 | if (launcher != null) { 54 | shell.setVariable("launcher", launcher); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/scriptSettings.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | title=Create a new Groovy script 23 | intro=\ 24 | Type in an arbitrary Groovy script and \ 25 | save it. Later you will be able to execute it on any agent. Useful for troubleshooting and diagnostics. \ 26 | Use the ''println'' command to see the output (if you use System.out, \ 27 | it will go to the server''s stdout, which is harder to see.). If you think your script might be useful to others too, please share it on https://github.com/jenkinsci/jenkins-scripts. 28 | uploadtext=Select a Groovy script from your local system to be uploaded (*.groovy). 29 | UploadEncoding=Uploaded files should be encoded with UTF-8. 30 | Permission = Allow usage in build step 31 | Restriction = Restriction 32 | RestrictionDescription = Script is always executed on the built-in node 33 | Example=Example: 34 | Name=Name 35 | Comment=Comment 36 | Script=Script 37 | Submit=Submit 38 | Upload\ new\ Script=Upload new Script 39 | Upload=Upload 40 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/runScript.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | title=Run a script 24 | intro=Please select an agent you would like to run the script on. You can also modify the script to your needs, the changes will not affect the stored version of it!

\ 25 | You can also run a script using POST to the URL /scriptler/run/<your-script-id> with the optional parameters node, script (alternative script text), contentType, and the parameters defined for your stored script. 26 | modificationRequiredApproval=As you lack the Overall/RunScripts permission, your modifications will be put in the script approval queue. You can still run the script as is. 27 | executiononclient=This execution happens in the agent JVM... 28 | SelectionNode=Select a node 29 | ParametersDescription=Define script parameters 30 | Parameters=Parameters 31 | ParameterName=Name: 32 | ParameterValue=Value: 33 | Run=Run 34 | Result=Result 35 | ScriptNotFound=// Script source file was not found 36 | NotApprovedYet=Script not yet approved, consider asking your administrator to approve it. 37 | NotApprovedYetButHasRightWarn=Script not yet approved 38 | NotApprovedYetButHasRightInfo=By running it you will automatically approve it. 39 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/sidepanel.jelly: -------------------------------------------------------------------------------- 1 | 2 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/settings.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | 24 | 26 | 27 | 28 | 29 |

30 | ${%title} 31 |

32 | 33 | ${%intro} 34 |

${%Directories}

35 | ${%scriptlerdirectorytext} ${it.scriptlerHomeDirectory}
36 | ${%scriptdirectorytext} ${it.scriptDirectory} 37 |

38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | ${%disabledtext} 52 |
53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/tokenmacro/ScriptlerTokenMacro.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.tokenmacro; 2 | 3 | import hudson.Extension; 4 | import hudson.FilePath; 5 | import hudson.model.AbstractBuild; 6 | import hudson.model.TaskListener; 7 | import hudson.remoting.Channel; 8 | import hudson.remoting.ChannelClosedException; 9 | import hudson.remoting.VirtualChannel; 10 | import java.io.IOException; 11 | import java.util.List; 12 | import jenkins.model.Jenkins; 13 | import org.jenkinsci.plugins.scriptler.Messages; 14 | import org.jenkinsci.plugins.scriptler.config.Script; 15 | import org.jenkinsci.plugins.scriptler.util.ControllerGroovyScript; 16 | import org.jenkinsci.plugins.scriptler.util.GroovyScript; 17 | import org.jenkinsci.plugins.scriptler.util.ScriptHelper; 18 | import org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro; 19 | import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException; 20 | 21 | /** 22 | * TokenMacro that allows the execution of a scriptler script an any arbitrary location supporting TokenMacros e.g. ${SCRIPTLER, scriptId="superscript.groovy"} 23 | * 24 | * @author Dominik Bartholdi (imod) 25 | */ 26 | @Extension 27 | public class ScriptlerTokenMacro extends DataBoundTokenMacro { 28 | 29 | @Parameter 30 | public String scriptId; 31 | 32 | @Override 33 | public String evaluate(AbstractBuild context, TaskListener listener, String macroName) 34 | throws MacroEvaluationException, IOException, InterruptedException { 35 | 36 | final Script script = ScriptHelper.getScript(scriptId, true); 37 | if (script == null) { 38 | throw new MacroEvaluationException(Messages.tokenmacro_ScriptDoesNotExist(scriptId)); 39 | } else if (!script.nonAdministerUsing) { 40 | listener.getLogger().println(Messages.tokenmacro_AdminScriptOnly(scriptId)); 41 | throw new MacroEvaluationException(Messages.tokenmacro_AdminScriptOnly(scriptId)); 42 | } 43 | 44 | String scriptText = script.getScriptText(); 45 | VirtualChannel channel; 46 | GroovyScript groovyScript; 47 | if (script.onlyBuiltIn || Jenkins.get().equals(context.getBuiltOn())) { 48 | channel = FilePath.localChannel; 49 | groovyScript = new ControllerGroovyScript(scriptText, List.of(), true, listener, null, context); 50 | } else { 51 | FilePath remoteFilePath = context.getWorkspace(); 52 | if (remoteFilePath == null) { 53 | // the remote node has apparently disconnected, so we can't run our script 54 | throw new ChannelClosedException((Channel) null, null); 55 | } 56 | channel = remoteFilePath.getChannel(); 57 | groovyScript = new GroovyScript(scriptText, List.of(), true, listener); 58 | } 59 | 60 | Object output = channel.call(groovyScript); 61 | return output != null ? output.toString() : ""; 62 | } 63 | 64 | @Override 65 | public boolean acceptsMacroName(String macroName) { 66 | return macroName.equals("SCRIPTLER"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/webapp/lib/scriptler.js: -------------------------------------------------------------------------------- 1 | function scriptler_initDetailLink(rootUrl, referenceTag) { 2 | var itemUrl = referenceTag.dataset.itemUrl; 3 | var selId = referenceTag.value; 4 | var all = new Array(); 5 | all = document.getElementsByName("scriptlerScriptId"); 6 | for (var i = 0; i < all.length; i++) { 7 | if (referenceTag == all.item(i)) { 8 | var detailsLinkTag = document.getElementsByName("showScriptlerDetailLink").item(i); 9 | if (selId.length != 0) { 10 | detailsLinkTag.href = rootUrl + "/" + itemUrl + "scriptler/showScript?id=".concat(selId); 11 | detailsLinkTag.style.display = "block"; 12 | } else { 13 | detailsLinkTag.style.display = "none"; 14 | } 15 | } 16 | } 17 | } 18 | 19 | function scriptler_descArguments(referenceTag, params) { 20 | var all = new Array(); 21 | all = document.getElementsByName("scriptlerScriptId"); 22 | for (var i = 0; i < all.length; i++) { 23 | if (referenceTag == all.item(i)) { 24 | var desc = ""; 25 | for (var j = 0; j < params.length; j++) { 26 | desc += j + ": " + params[j].name + " "; 27 | } 28 | var descriptionTag = document.getElementsByName("scriptlerParameters").item(i); 29 | descriptionTag.innerText = desc; 30 | } 31 | } 32 | } 33 | 34 | function scriptler_showParams(referenceTag, scriptId) { 35 | scriptlerBuilderDesc.getParameters(scriptId, function (t) { 36 | var params = t.responseObject(); 37 | if (params != null) { 38 | scriptler_descArguments(referenceTag, params); 39 | } 40 | }); 41 | } 42 | 43 | Behaviour.specify("select[name='scriptlerScriptId']", "ScriptlerBuilderSelect", 0, function (element) { 44 | const script = document.querySelector("#scriptler-builder-behaviour"); 45 | const rootUrl = script.dataset.rootUrl; 46 | element.addEventListener("change", function (event) { 47 | const target = event.target; 48 | scriptler_initDetailLink(rootUrl, target); 49 | scriptler_showParams(target, target.value); 50 | }); 51 | }); 52 | 53 | Behaviour.specify("a[name='showScriptlerDetailLink']", "ScriptlerBuilderDetailLink", 0, function (element) { 54 | element.addEventListener("click", function (event) { 55 | event.preventDefault(); 56 | const target = event.target; 57 | window.open(target.href, "window", "width=900,height=640,resizable,scrollbars,toolbar,menubar"); 58 | }); 59 | }); 60 | 61 | document.addEventListener("DOMContentLoaded", function () { 62 | const script = document.querySelector("#scriptler-builder-behaviour"); 63 | const rootUrl = script.dataset.rootUrl; 64 | const hasPermission = script.dataset.hasPermission; 65 | 66 | var all = new Array(); 67 | all = document.getElementsByName("scriptlerScriptId"); 68 | for (var i = 0; i < all.length; i++) { 69 | all.item(i).disabled = !hasPermission; 70 | scriptler_initDetailLink(rootUrl, all.item(i)); 71 | scriptler_showParams(all.item(i), all.item(i).value); 72 | } 73 | 74 | // remember the job name to send it along with the form 75 | var jobName = document.getElementsByName("name").item(0).value; 76 | var allBackupJobNames = document.getElementsByName("backupJobName"); 77 | for (var i = 0; i < allBackupJobNames.length; i++) { 78 | allBackupJobNames.item(i).value = jobName; 79 | } 80 | }); 81 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/Messages.properties: -------------------------------------------------------------------------------- 1 | # The MIT License 2 | # 3 | # Copyright (c) 2009-2010, Dominik Bartholdi 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 13 | # all 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 21 | # THE SOFTWARE. 22 | 23 | display_name=Scriptler 24 | description=Store/edit/run scripts on any of the agents or the built-in node. 25 | scriptdirectorytitle=The scripts are stored at: 26 | not_groovy_script=this is not a groovy script: {0} 27 | script_loaded_from_directory=this script was discovered on the file system, please describe it! 28 | uploadtext=Select a Groovy script from your local system to be uploaded. 29 | node_not_found=The node [{0}] could not be found! 30 | node_not_online=The selected node [{0}] is not online, therefore the script can not be executed! Select another node or start it before you try again. 31 | agent_no_channel=No channel to the agent 32 | download_failed=The import of the script [{0}] from catalog [{1}] failed. 33 | builder_name=Scriptler script 34 | scriptNotFound = could not find script with id [{0}] 35 | scriptNotDefined = there is no script for scriptler defined, please fix your configuration! 36 | scriptNotUsableInBuildStep = The script [{0}] is not usable in a build step, please review your configuration. 37 | scriptNotApprovedYet = The script [{0}] is not yet approved, consider asking your administrator to approve it. 38 | scriptExecutionFailed = Execution of script [{0}] failed 39 | parameterExtractionFailed = failed to read parameters from request 40 | scriptSourceNotFound = not able to load sources for script [{0}] 41 | skipParameter = skipping parameter [{0}] this name is used internal, please rename! 42 | resultPrefix = Result: 43 | no_parameters_defined = There is not any parameter defined for this job. 44 | tokenmacro_AdminScriptOnly = The script [{0}] exists, but is marked to be used by admins only and is therefore not allowed for usage in the TokenMacro. 45 | tokenmacro_ScriptDoesNotExist = No script with the id [{0}] could be found. 46 | permissons_title = Scriptler 47 | permissons_configure_description = Allow configuration of Scriptler scripts, allow fine grain tuning instead of giving Overall/RunScripts to everyone 48 | permissons_runScript_description = Allow execution of Scriptler scripts and insertion / modification of Scriptler build steps, allow fine grain tuning instead of giving Overall/RunScripts to everyone 49 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/scriptler/ScriptlerManagement/scriptSettings.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 22 | 23 | 24 | 26 | 27 | 28 | 29 |

${%title}

30 |

31 | ${%intro} 32 |
33 | ${%Example} 34 |

println System.getenv("PATH")
35 |

36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 70 | 71 |
72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/share/gh/GHCatalog.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler.share.gh; 2 | 3 | import edu.umd.cs.findbugs.annotations.CheckForNull; 4 | import hudson.Extension; 5 | import hudson.ProxyConfiguration; 6 | import java.io.IOException; 7 | import java.net.URI; 8 | import java.net.URISyntaxException; 9 | import java.net.http.HttpClient; 10 | import java.net.http.HttpRequest; 11 | import java.net.http.HttpResponse; 12 | import java.nio.charset.StandardCharsets; 13 | import java.util.ArrayList; 14 | import java.util.Collection; 15 | import java.util.Comparator; 16 | import java.util.List; 17 | import java.util.logging.Level; 18 | import java.util.logging.Logger; 19 | import org.jenkinsci.plugins.scriptler.share.CatalogInfo; 20 | import org.jenkinsci.plugins.scriptler.share.ScriptInfo; 21 | import org.jenkinsci.plugins.scriptler.share.ScriptInfoCatalog; 22 | 23 | /** 24 | * Provides access to the scriptler scripts shared at jenkinsci/jenkins-scripts 25 | * 26 | * @author Dominik Bartholdi (imod) 27 | * 28 | */ 29 | @Extension(ordinal = 10) 30 | public class GHCatalog implements ScriptInfoCatalog { 31 | 32 | private static final Logger LOGGER = Logger.getLogger(GHCatalog.class.getName()); 33 | 34 | private static final String REPO = "jenkinsci/jenkins-scripts"; 35 | private static final String BRANCH = "main"; 36 | public static final String REPO_BASE = "https://github.com/" + REPO + "/blob/" + BRANCH + "/scriptler/{1}"; 37 | public static final String DOWNLOAD_URL = "https://raw.github.com/" + REPO + "/" + BRANCH + "/scriptler/{1}"; 38 | 39 | public static final CatalogInfo CATALOG_INFO = new CatalogInfo("gh", REPO_BASE, REPO_BASE, DOWNLOAD_URL); 40 | 41 | @Override 42 | public List getEntries() { 43 | return getEntries(ScriptInfo.COMPARATOR_BY_NAME); 44 | } 45 | 46 | @Override 47 | public String getDisplayName() { 48 | return "GitHub"; 49 | } 50 | 51 | @Override 52 | public ScriptInfo getEntryById(String id) { 53 | for (ScriptInfo info : getEntries(null)) { 54 | if (id.equals(info.getId())) { 55 | return info; 56 | } 57 | } 58 | return null; 59 | } 60 | 61 | private List getEntries(@CheckForNull Comparator comparator) { 62 | Collection scriptInfoList = List.of(); 63 | try { 64 | scriptInfoList = CentralScriptJsonCatalog.getCatalog().getScripts(); 65 | } catch (IOException e) { 66 | LOGGER.log(Level.SEVERE, "not abe to load script infos from GH", e); 67 | } 68 | List sortedScriptInfoList = new ArrayList<>(scriptInfoList); 69 | 70 | if (comparator != null) sortedScriptInfoList.sort(comparator); 71 | 72 | return sortedScriptInfoList; 73 | } 74 | 75 | @Override 76 | public CatalogInfo getInfo() { 77 | return CATALOG_INFO; 78 | } 79 | 80 | @Override 81 | public String getScriptSource(ScriptInfo scriptInfo) { 82 | 83 | final String scriptUrl = CATALOG_INFO.getReplacedDownloadUrl(scriptInfo.getName(), scriptInfo.getId()); 84 | try { 85 | HttpClient client = ProxyConfiguration.newHttpClient(); 86 | HttpRequest request = 87 | ProxyConfiguration.newHttpRequestBuilder(new URI(scriptUrl)).build(); 88 | return client.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)) 89 | .body(); 90 | } catch (InterruptedException e) { 91 | LOGGER.log(Level.SEVERE, e, () -> "not able to load script sources from GH for: " + scriptInfo); 92 | Thread.currentThread().interrupt(); 93 | } catch (IOException | URISyntaxException e) { 94 | LOGGER.log(Level.SEVERE, e, () -> "not able to load script sources from GH for: " + scriptInfo); 95 | } 96 | 97 | return null; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/scriptler/SyncUtil.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.scriptler; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.nio.file.Files; 6 | import java.nio.file.Path; 7 | import java.util.*; 8 | import java.util.logging.Level; 9 | import java.util.logging.Logger; 10 | import java.util.stream.Stream; 11 | import org.jenkinsci.plugins.scriptler.config.Parameter; 12 | import org.jenkinsci.plugins.scriptler.config.Script; 13 | import org.jenkinsci.plugins.scriptler.config.ScriptlerConfiguration; 14 | import org.jenkinsci.plugins.scriptler.share.ScriptInfo; 15 | import org.jenkinsci.plugins.scriptler.util.ScriptHelper; 16 | 17 | public class SyncUtil { 18 | 19 | private static final Logger LOGGER = Logger.getLogger(SyncUtil.class.getName()); 20 | 21 | private SyncUtil() {} 22 | 23 | /** 24 | * @deprecated Use {@link #syncDirWithCfg(Path, ScriptlerConfiguration)} instead. 25 | */ 26 | @Deprecated(since = "380") 27 | public static void syncDirWithCfg(File scriptDirectory, ScriptlerConfiguration cfg) throws IOException { 28 | syncDirWithCfg(scriptDirectory.toPath(), cfg); 29 | } 30 | 31 | /** 32 | * must be saved (by caller) after finishing this all sync 33 | */ 34 | public static void syncDirWithCfg(Path scriptDirectory, ScriptlerConfiguration cfg) throws IOException { 35 | 36 | List availablePhysicalScripts = getAvailableScripts(scriptDirectory); 37 | 38 | // check if all physical files are available in the configuration 39 | // if not, add it to the configuration 40 | for (Path file : availablePhysicalScripts) { 41 | final String fileName = Objects.toString(file.getFileName(), null); 42 | if (cfg.getScriptById(fileName) == null) { 43 | final ScriptInfo info = ScriptHelper.extractScriptInfo(ScriptHelper.readScriptFromFile(file)); 44 | if (info != null) { 45 | List parameters = info.getParameters().stream() 46 | .map(name -> new Parameter(name, null)) 47 | .toList(); 48 | cfg.addOrReplace(new Script(fileName, info.getName(), info.getComment(), false, parameters, false)); 49 | } else { 50 | cfg.addOrReplace(new Script( 51 | fileName, 52 | fileName, 53 | Messages.script_loaded_from_directory(), 54 | false, 55 | Collections.emptyList(), 56 | false)); 57 | } 58 | } 59 | } 60 | 61 | // check if all scripts in the configuration are physically available 62 | // if not, mark it as missing 63 | Set