Skip to content

feat(windows-plugin): add cmd.exe-based plugin for executing .exe fil… #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

balaaparna-dev
Copy link

@balaaparna-dev balaaparna-dev commented May 11, 2025

Closes kestra-io/kestra#2510.

What changes are being made and why?

To Enable Windows Command Execution

The task supports use cases such as:

  • Running .exe files.
  • Interacting with the local file system .
    related to issue #2510.

How the changes have been QAed?

Two unit tests were implemented in the WindowsCmdTaskTest class to validate the functionality of the WindowsCmdTask implementation:
testSimpleCommand: Verifies that a valid command (echo Hello, World!) executes successfully and produces the expected output.
testInvalidCommand: Ensures that an invalid command (invalidcommand) is handled gracefully by throwing an appropriate exception.

…es and interacting with local file system (#2510)
@MilosPaunovic
Copy link
Member

Just a small note for the future, if you could use GitHub Keywords when opening PRs to connect it to the proper issue (to automate the entire process a bit more), it would be super helpful to us. You can read a bit more about it here (I've added closing keyword for this particular issue).

@MilosPaunovic MilosPaunovic requested review from a team and Malaydewangan09 May 16, 2025 06:15
@Malaydewangan09 Malaydewangan09 requested review from fdelbrayelle and removed request for Malaydewangan09 May 23, 2025 05:54
@fdelbrayelle fdelbrayelle added enhancement New feature or request area/plugin Plugin-related issue or feature request labels May 26, 2025
Copy link
Contributor

@fdelbrayelle fdelbrayelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, well done!

Could you remove the bin folder from the PR please and add plugin-script-windows/bin to the .gitignore?

Also, could you add a sanity check flow test (by adding a full flow in YAML in src/test/resources)?

Finally, maybe it could make also sense to have a second task Script taking batch script as a Strig property (like it's done in .bat files even if Powershell is a more modern approach for Windows scripts) like this one:

@echo off
echo Hello World!
REM

What do you think about this last one @anna-geller ?

attributes(
"X-Kestra-Name": project.name,
"X-Kestra-Title": "Windows Command Task",
"X-Kestra-Group": project.group + ".windows",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"X-Kestra-Group": project.group + ".windows",
"X-Kestra-Group": project.group + ".scripts.windows",

)
}
)
public class WindowsCmdTask implements RunnableTask<WindowsCmdTask.Output> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the task like this so that it follows the other plugin-scripts tasks naming please?

cc @anna-geller What do you think about it?

Suggested change
public class WindowsCmdTask implements RunnableTask<WindowsCmdTask.Output> {
public class Commands implements RunnableTask<WindowsCmdTask.Output> {

Comment on lines +36 to +47
@Example(
title = "List files in a directory",
code = {
"command: \"dir\""
}
),
@Example(
title = "Run an executable file",
code = {
"command: \"C:\\\\path\\\\to\\\\program.exe\""
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For each example, you need to provide a full flow like this:

    @Example(
        full = true,
        title = "Execute Windows commands.",
        code = """
            id: execute_windows_commands
            namespace: company.team

            tasks:
              - id: windows
                type: io.kestra.plugin.scripts.windows.Commands
                commands:
                  - dir
            """
    )

Comment on lines +66 to +67
@PluginProperty(dynamic = true)
private String command;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The annotation @PluginProperty is the old way to do. Can you please for all properties do like this?

Suggested change
@PluginProperty(dynamic = true)
private String command;
private Property<String> command;

Comment on lines +1 to +5
tasks:
- id: windows-cmd-task
name: Windows Command Task
description: Execute Windows commands using cmd.exe
class: io.kestra.plugin.scripts.windows.WindowsCmdTask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it used?

@anna-geller
Copy link
Member

anna-geller commented May 26, 2025

If you add a Script task next to commands task, best to refactor the code to follow what we've done on script Shell and script Powershell plugins with Script and Commands task

@anna-geller
Copy link
Member

@Ben8t @aj-emerich FYI the planned syntax for this plugin is below (confirmed with @fdelbrayelle):

id: windows
namespace: company.team

tasks:
  - id: cli
    type: io.kestra.plugin.scripts.windows.Commands
    commands:
      - dir

  - id: script
    type: io.kestra.plugin.scripts.windows.Script
    script: |
      @echo off
      cls
      rem This is a comment
      echo Hello World!
      pause     

@fdelbrayelle
Copy link
Contributor

@balaaparna-dev Could you also add an icon io.kestra.plugin.scripts.windows.svg in src/main/resources please (maybe the Windows logo)?

@balaaparna-dev
Copy link
Author

Thank you for the update. I’ll address the feedback and follow up shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/plugin Plugin-related issue or feature request enhancement New feature or request
Projects
Status: To review
Development

Successfully merging this pull request may close these issues.

Add a Windows plugin with cmd.exe task
4 participants