Home > Software design >  Running GitHub scripts directly from Rundeck
Running GitHub scripts directly from Rundeck

Time:01-07

I have a Windows server running the community version of Rundeck, and I want to be able to run PowerShell scripts directly from my private GitHub repository, by providing the URL of the script.

enter image description here

On GitHub, I have created a personal access token that doesn't expire, because I'm running multiple jobs on Rundeck and I don't want to be modifying each job, every time a token expires.

I've tried various ways to do this but nothing works.

  • providing the username and password in the URL
  • providing the username and access token in the URL

https://$username:[email protected]/$username/general/main/rundeck/$script.ps1

https://$username:[email protected]/$username/general/main/rundeck/$script.ps1

I know that at some point GitHub disabled password authentication in the URL, so I'm looking for an alternative way to do it.

If it's possible I don't want to clone the git repository. I want to use a link to the raw script and run it directly.

CodePudding user response:

It works in the following way:

  1. On GitHub Go to your Avatar icon (up to right) > Settings > Developer Settings (left menu) > Personal Access Token > Tokens.

  2. Click on the "Generate new token" button (up to right) > Generate new token (classic). Make sure to create a token with enough rights to read your repository. Save this token value.

  3. On Rundeck, create a new job and add "Script file or URL", on the "File Path/URL" field put the remote path with the following format: https://<your_github_user_name>:<your_user_token>@raw.githubusercontent.com/username/repository/branch/your_script.sh

I made a job definition example that works (tested on Rundeck 4.8.0):

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 5f74a444-7b2f-4e50-af96-ca770c9d038e
  loglevel: INFO
  name: RemoteScriptTest
  nodeFilterEditable: false
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - fileExtension: .sh
      interpreterArgsQuoted: false
      scriptInterpreter: /bin/bash
      scripturl: https://user:[email protected]/user/scripts/main/myscript.sh
    keepgoing: false
    strategy: node-first
  uuid: 5f74a444-7b2f-4e50-af96-ca770c9d038e

This example calls a bash script but you can use Powershell to define powershell.exe on the "Invocation String" and .ps1 on the "File extension" text boxes.

Note: if you want to use an option to store the token, use the ${option.myoption} format, here is another example:

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: 5f74a444-7b2f-4e50-af96-ca770c9d038e
  loglevel: INFO
  name: RemoteScriptTest
  nodeFilterEditable: false
  options:
  - name: mytoken
    value: abc123
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - fileExtension: .sh
      interpreterArgsQuoted: false
      scriptInterpreter: /bin/bash
      scripturl: https://user:${option.mytoken}@raw.githubusercontent.com/user/scripts/main/myscript.sh
    keepgoing: false
    strategy: node-first
  uuid: 5f74a444-7b2f-4e50-af96-ca770c9d038e

  • Related