Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot execute pwsh as shell commands #660

Closed
1 task done
jetersen opened this issue Apr 23, 2022 · 15 comments
Closed
1 task done

Cannot execute pwsh as shell commands #660

jetersen opened this issue Apr 23, 2022 · 15 comments
Labels
bug Something isn't working

Comments

@jetersen
Copy link
Member

jetersen commented Apr 23, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

TARGETS
========

default
-------

**Dry Run enabled**

The shell 馃悮 command "pwsh -File ./updatecli/updatecli.d/test.ps1 2.344" exited on error (exit code 64) with the following output:
----

Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
                  [-Command { - | <script-block> [-args <arg-array>]
                                | <string> [<CommandParameters>] } ]
                  [-ConfigurationName <string>] [-CustomPipeName <string>]
                  [-EncodedCommand <Base64EncodedCommand>]
                  [-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
                  [-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
                  [-OutputFormat {Text | XML}] [-SettingsFile <filePath>] [-SSHServerMode] [-STA]
                  [-Version] [-WindowStyle <style>] [-WorkingDirectory <directoryPath>]

       pwsh[.exe] -h | -Help | -? | /?

PowerShell Online Help https://aka.ms/powershell-docs

All parameters are case-insensitive.
----

command stderr output was:
----
The argument './updatecli/updatecli.d/test.ps1' is not recognized as the name of a script file. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

----
ERROR: Something went wrong in target "default" :
ERROR: Shell command exited on error.

Expected Behavior

Runs the powershell script 馃槄

Steps To Reproduce

---
scms:
  github:
    kind: github
    spec:
      user: "{{ .github.user }}"
      email: "{{ .github.email }}"
      owner: "{{ .github.owner }}"
      repository: "{{ .github.repository }}"
      token: "{{ requiredEnv .github.token }}"
      username: "{{ .github.username }}"
      branch: "{{ .github.branch }}"

sources:
  jenkinsWeekly:
    name: Get Last Jenkins Weekly Version
    kind: jenkins
    spec:
      release: weekly
      github:
        token: "{{ requiredEnv .github.token }}"
        username: "{{ .github.username }}"
conditions:
  jenkinsWeekly:
    name: Test if Jenkins weekly published
    kind: maven
    spec:
      url: "repo.jenkins-ci.org"
      repository: "releases"
      groupid: "org.jenkins-ci.main"
      artifactid: "jenkins-war"
targets:
  default:
    name: 'Update weekly version'
    sourceid: jenkinsWeekly
    kind: shell
    spec:
      command: pwsh -File ./updatecli/updatecli.d/test.ps1
    scmid: github

Environment

OS: Ubuntu 20.04
updatecli: v0.23.2

Anything else?

I would like to use powershell as it has a decent way of interacting with XML while #336 #371 is still WIP

@jetersen jetersen added the bug Something isn't working label Apr 23, 2022
@olblak
Copy link
Member

olblak commented Apr 25, 2022

interesting, did you try running updatecli with the flag --clean=false such updatecli diff --config <you manifest> --clean=false --debug

The goal is to not delete the git repository from /tmp/updatecli then check if you correctly have the script ./updatecli/updatecli.d/test.ps1, on the branch from that repository

@jetersen
Copy link
Member Author

I think maybe my issue was related to the fact that I cannot develop new scripts and test those locally with updatecli which is rather confusing.

@dduportal
Copy link
Contributor

That definitively looks like a bug to me. I was never able to test updatecli on a Windows machine so can't be sure.

Given how I found hard to execute shell command with Go on Linux, I really do not trust my code on that area :D

@olblak
Copy link
Member

olblak commented Apr 25, 2022

I think maybe my issue was related to the fact that I cannot develop new scripts and test those locally with updatecli which is rather confusing.

You aren't the only one to find this confusing.
@dduportal is trying to refactor this behavior, feel free to provide feedbacks on #465

@dduportal
Copy link
Contributor

I think maybe my issue was related to the fact that I cannot develop new scripts and test those locally with updatecli which is rather confusing.

You aren't the only one to find this confusing. @dduportal is trying to refactor this behavior, feel free to provide feedbacks on #465

@olblak I really think that it's unrelated to "diff" / "pullrequest" / "actions", but with how Windows is handled when running a "shell" command with the updatcli binary on Windows

@olblak
Copy link
Member

olblak commented Apr 25, 2022

but in this case, @jetersen mentioned that he was on Ubuntu

@jetersen
Copy link
Member Author

Again my confusion is that updatecli for the shell command uses the tmp folder as a working directory.
Which is quite confusing when developing a new script that has not been committed.

Maybe we need an option to run on the current git clone that assumes dry run.
So you can test the updatecli behavior.

@olblak
Copy link
Member

olblak commented Apr 26, 2022

Again my confusion is that updatecli for the shell command uses the tmp folder as a working directory.

You are not the first one to find this behavior confusing.
We've been discussing about it a lot with @dduportal on how to improve the user experience.

Up to now, relying on a temporary directory make things safer.
But it's really annoying as we can't easily test manifest that modify files which are not yet available on the remote environment. At least, without commenting all the scm stuff.

The biggest challenge comes from the fact that a manifest can have multiple scm configuration that may have nothing to do with the local repository.

@olblak
Copy link
Member

olblak commented Apr 26, 2022

Maybe we need an option to run on the current git clone that assumes dry run.
So you can test the updatecli behavior.

That's part of @dduportal refactoring with #465

## New flag that ensures that the target is applied locally but the "actions" are not applied
$ updatecli apply --config manifest.yaml --values values.yaml --no-actions # Or --actions=false

You may send him a beer or two to motivate him ;)

@jetersen
Copy link
Member Author

You may send him a beer or two to motivate him ;)

@dduportal has not setup his GitHub sponsor 馃槄

@dduportal
Copy link
Contributor

You may send him a beer or two to motivate him ;)

@dduportal has not setup his GitHub sponsor 馃槄

I'm the Internet Explorer of the open source: Just realizing what GitHub Sponsor exists and what is it :D

@jetersen
Copy link
Member Author

I think we can close this issue and link to #465

I have verified I am able to perform powershell scripts over here: jenkinsci/bom#1279

FYI updatecli and the powershell script is really useful for managing pinned version.

@olblak
Copy link
Member

olblak commented Jul 20, 2022

FYI updatecli and the powershell script is really useful for managing pinned version.

I think that could be a great story to publish on www.updatecli.io :)
and a great learning experience for me

@jetersen
Copy link
Member Author

jetersen commented Jul 20, 2022

Would be a better story if #754 was there! Cause right now pwsh terminal relies on process environment variables inheritance and without #754 I have problems accessing curl and java as well as getting the correct path to the jenkins plugin manager jar. 馃槗

@jetersen
Copy link
Member Author

jetersen commented Jul 27, 2022

My solution ended up being simple: https://github.com/jenkinsci/bom/blob/72a2154456b19142082e63d7195b4e82a3848dcf/updatecli/generate-manifests.ps1#L118

targets:
  jenkins:
    kind: shell
    spec:
      command: pwsh -NoProfile -File {{ requiredEnv "GITHUB_WORKSPACE" }}/updatecli/update-jenkins.ps1

This allows me to always use the correct shell script even when updating it.

The powershell scripting ended up being useful to fully generate everything inside the bom's multiple pom.xml into updatecli manifests.

Now we just need an updatecli with auto discovery and no manifests.

But ya teaching updatecli about pom.xml and use cases like https://github.com/jenkinsci/bom might be hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

3 participants