Run pipeline against different targets

Hi,

i have a file with 2 very large pipelines with many steps in there. The first one is a docker pipeline with many calls to drone-scp for copying files the a targetserver. The other one is a ssh-runner, which executes several steps on the targetserver. I want to execute both pipelines to several server (lets say dev/int and prod) without copying them, in best case by using variables. But i didn’t understand how to do that? Is it possible to set the connection values (host, key, port, …) from a variable from drone-scp as well as the ssh runner?

Possibly i ask a silly question, i am new to drone but didn’t find anything towards that topic in the documentation.

Thanks in advance

Dave

If the goal is to keep your pipeline configuration DRY (without repeating yourself) you can use jsonnet or starlark configuration options, as opposed to yaml. Both are supported in the latest version of the Drone server, but need to be enabled first.

Hi,

i definitivly don’t want to learn the next scripting language. But i found a solution, i want to share here, because i found no other documentation at the web which does the same. Hope that will sweeten the day of some people.
First i define a template with anchors for every pipeline step type:

kind: pipeline
type: docker
name: Jenkins management

steps:

######### TEMPLATES #########

- name: SCP template
  image: &imagescp appleboy/drone-scp
  settings: &settingsscp
    host: TARGETHOST
    username: AUSERWHICHEXISTONBOTSYSTEMS
    key:
      from_secret: APRIVATEKEYWHICHEXISTONBOTHSYSTEMS
    port: 22
    target: /home/AUSERWHICHEXISTONBOTSYSTEMS
    source: SOURCEFILE
  when:
    target:
    - template

- name: SSH template
  image: &imagessh appleboy/drone-ssh
  settings: &settingsssh
    host: TARGETHOST
    username: AUSERWHICHEXISTONBOTSYSTEMS
    key:
      from_secret: APRIVATEKEYWHICHEXISTONBOTHSYSTEMS
    port: 22
    script: &scriptssh
      - echo step 1
      - echo step 2
      - echo $${OIDC_CLIENT_SECRET} # variable defined in action step below
      - echo do 10000 additional steps here
  when:
    target:
    - template
###
# other templates for drone-ssh, ... here..
###

This both steps should never run. That’s the reason for template target.
If you want to run an action against a docker container, do not forget to transfer the variables in the docker container as well. example:

- docker exec --env OIDC_CLIENT_SECRET=$${OIDC_CLIENT_SECRET} mycontainer bash -c 'echo $${OIDC_CLIENT_SECRET}'

Now i create the actions for PRD and DEV, based on the templates:

######### COPY mysourcefile.xml #########

- name: DEV-SCP Copy something
  image: *imagescp
  settings:
    <<: *settingsscp
    host: YOURDEVTARGETSERVER
    source: mysourcefile.xml
  when:
    target:
    - DEV

- name: PRD-SCP Copy jobTemplate
  image: *imagescp
  settings:
    <<: *settingsscp
    host: YOURPRDTARGETSERVER
    source: mysourcefile.xml
  when:
    target:
    - PRD

######### Do the magic here #########

- name: DEV-SSH Manage Server
  image: *imagessh
  environment:
    OIDC_CLIENT_SECRET:
      from_secret: oidc-client-secret-dev
  settings:
    <<: *settingsssh
    host: YOURDEVTARGETSERVER
    envs:
      - OIDC_CLIENT_SECRET
    script: *scriptssh
  when:
    target:
    - DEV

- name: PRD-SSH Manage Jenkins
  image: *imagessh
  environment:
    OIDC_CLIENT_SECRET:
      from_secret: oidc-client-secret-prd
  settings:
    <<: *settingsssh
    host: YOURPRDTARGETSERVER
    envs:
      - OIDC_CLIENT_SECRET
    script: *scriptssh
  when:
    target:
    - PRD