github.com/alloyci/alloy-runner@v1.0.1-0.20180222164613-925503ccafd6/docs/shells/README.md (about)

     1  # Shells supported by AlloyCI Runner
     2  
     3  AlloyCI Runner implements a few shell script generators that allow to execute
     4  builds on different systems.
     5  
     6  ## Overview
     7  
     8  The shell scripts contain commands to execute all steps of the build:
     9  
    10  1. `git clone`
    11  1. Restore the build cache
    12  1. Build commands
    13  1. Update the build cache
    14  1. Generate and upload the build artifacts
    15  
    16  The shells don't have any configuration options. The build steps are received
    17  from the commands defined in the [`script` directive in `.alloy-ci.json`][script].
    18  
    19  The currently supported shells are:
    20  
    21  | Shell         | Description |
    22  | --------------| ----------- |
    23  | `bash`        | Bash (Bourne-shell) shell. All commands executed in Bash context (default for all Unix systems) |
    24  | `sh`          | Sh (Bourne-shell) shell. All commands executed in Sh context (fallback for `bash` for all Unix systems) |
    25  | `cmd`         | Windows Batch script. All commands are executed in Batch context (default for Windows) |
    26  | `powershell`  | Windows PowerShell script. All commands are executed in PowerShell context |
    27  
    28  ## Sh/Bash shells
    29  
    30  This is the default shell used on all Unix based systems. The bash script used
    31  in `.alloy-ci.json` is executed by piping the shell script to one of the
    32  following commands:
    33  
    34  ```bash
    35  # This command is used if the build should be executed in context
    36  # of another user (the shell executor)
    37  cat generated-bash-script | su --shell /bin/bash --login user
    38  
    39  # This command is used if the build should be executed using
    40  # the current user, but in a login environment
    41  cat generated-bash-script | /bin/bash --login
    42  
    43  # This command is used if the build should be executed in
    44  # a Docker environment
    45  cat generated-bash-script | /bin/bash
    46  ```
    47  
    48  ## Windows Batch
    49  
    50  This is the default shell used on Windows. Windows Batch doesn't support
    51  executing the build in context of another user.
    52  
    53  The generated Batch script is executed by saving its content to file and
    54  passing the file name to the following command:
    55  
    56  ```bash
    57  cmd /Q /C generated-windows-batch.cmd
    58  ```
    59  
    60  This is how an example batch script looks like:
    61  
    62  ```bash
    63  @echo off
    64  setlocal enableextensions
    65  setlocal enableDelayedExpansion
    66  set nl=^
    67  
    68  
    69  echo Running on %COMPUTERNAME%...
    70  
    71  call :prescript
    72  IF %errorlevel% NEQ 0 exit /b %errorlevel%
    73  
    74  call :buildscript
    75  IF %errorlevel% NEQ 0 exit /b %errorlevel%
    76  
    77  call :postscript
    78  IF %errorlevel% NEQ 0 exit /b %errorlevel%
    79  
    80  goto :EOF
    81  :prescript
    82  SET CI=true
    83  SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
    84  SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
    85  SET CI_COMMIT_REF_NAME=master
    86  SET CI_JOB_ID=1
    87  SET CI_REPOSITORY_URL=http://alloy.example.com/group/project.git
    88  SET CI_PROJECT_ID=1
    89  SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
    90  SET CI_SERVER=yes
    91  SET CI_SERVER_NAME=AlloyCI CI
    92  SET CI_SERVER_VERSION=
    93  SET CI_SERVER_REVISION=
    94  SET GITLAB_CI=true
    95  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
    96  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
    97  SET GIT_SSL_CAINFO=C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
    98  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
    99  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   100  SET CI_SERVER_TLS_CA_FILE=C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   101  echo Cloning repository...
   102  rd /s /q "C:\AlloyCI-Runner\builds\0\project-1" 2>NUL 1>NUL
   103  "git" "clone" "http://alloy.example.com/group/project.git" "Z:/Gitlab/tests/test/builds/0/project-1"
   104  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   105  
   106  cd /D "C:\AlloyCI-Runner\builds\0\project-1"
   107  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   108  
   109  echo Checking out db45ad9a as master...
   110  "git" "checkout" "db45ad9af9d7af5e61b829442fd893d96e31250c"
   111  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   112  
   113  IF EXIST "..\..\..\cache\project-1\pages\master\cache.tgz" (
   114    echo Restoring cache...
   115    "alloy-runner-windows-amd64.exe" "extract" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz"
   116    IF %errorlevel% NEQ 0 exit /b %errorlevel%
   117  
   118  ) ELSE (
   119    IF EXIST "..\..\..\cache\project-1\pages\master\cache.tgz" (
   120      echo Restoring cache...
   121      "alloy-runner-windows-amd64.exe" "extract" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz"
   122      IF %errorlevel% NEQ 0 exit /b %errorlevel%
   123  
   124    )
   125  )
   126  goto :EOF
   127  
   128  :buildscript
   129  SET CI=true
   130  SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
   131  SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
   132  SET CI_COMMIT_REF_NAME=master
   133  SET CI_JOB_ID=1
   134  SET CI_REPOSITORY_URL=Z:\Gitlab\tests\test
   135  SET CI_PROJECT_ID=1
   136  SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
   137  SET CI_SERVER=yes
   138  SET CI_SERVER_NAME=AlloyCI
   139  SET CI_SERVER_VERSION=
   140  SET CI_SERVER_REVISION=
   141  SET GITLAB_CI=true
   142  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
   143  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
   144  SET GIT_SSL_CAINFO=C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
   145  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
   146  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   147  SET CI_SERVER_TLS_CA_FILE=C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   148  cd /D "C:\AlloyCI-Runner\builds\0\project-1"
   149  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   150  
   151  echo $ echo true
   152  echo true
   153  goto :EOF
   154  
   155  :postscript
   156  SET CI=true
   157  SET CI_COMMIT_REF=db45ad9af9d7af5e61b829442fd893d96e31250c
   158  SET CI_COMMIT_BEFORE_SHA=d63117656af6ff57d99e50cc270f854691f335ad
   159  SET CI_COMMIT_REF_NAME=master
   160  SET CI_JOB_ID=1
   161  SET CI_REPOSITORY_URL=Z:\Gitlab\tests\test
   162  SET CI_PROJECT_ID=1
   163  SET CI_PROJECT_DIR=Z:/Gitlab/tests/test/builds/0/project-1
   164  SET CI_SERVER=yes
   165  SET CI_SERVER_NAME=AlloyCI
   166  SET CI_SERVER_VERSION=
   167  SET CI_SERVER_REVISION=
   168  SET GITLAB_CI=true
   169  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
   170  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
   171  SET GIT_SSL_CAINFO=C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO
   172  md "C:\\AlloyCI-Runner\\builds\\0\\project-1.tmp" 2>NUL 1>NUL
   173  echo multiline!nl!tls!nl!chain > C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   174  SET CI_SERVER_TLS_CA_FILE=C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE
   175  cd /D "C:\AlloyCI-Runner\builds\0\project-1"
   176  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   177  
   178  echo Archiving cache...
   179  "alloy-runner-windows-amd64.exe" "archive" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz" "--path" "vendor"
   180  IF %errorlevel% NEQ 0 exit /b %errorlevel%
   181  
   182  goto :EOF
   183  ```
   184  
   185  ## PowerShell
   186  
   187  PowerShell doesn't support executing the build in context of another user.
   188  
   189  The generated PowerShell script is executed by saving it content to a file and
   190  passing the file name to the following command:
   191  
   192  ```bash
   193  powershell -noprofile -noninteractive -executionpolicy Bypass -command generated-windows-powershell.ps1
   194  ```
   195  
   196  This is how an example powershell script looks like:
   197  
   198  ```bash
   199  $ErrorActionPreference = "Stop"
   200  
   201  echo "Running on $env:computername..."
   202  
   203  & {
   204    $CI="true"
   205    $env:CI=$CI
   206    $CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
   207    $env:CI_COMMIT_REF=$CI_COMMIT_REF
   208    $CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
   209    $env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
   210    $CI_COMMIT_REF_NAME="master"
   211    $env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
   212    $CI_JOB_ID="1"
   213    $env:CI_JOB_ID=$CI_JOB_ID
   214    $CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
   215    $env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
   216    $CI_PROJECT_ID="1"
   217    $env:CI_PROJECT_ID=$CI_PROJECT_ID
   218    $CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
   219    $env:CI_PROJECT_DIR=$CI_PROJECT_DIR
   220    $CI_SERVER="yes"
   221    $env:CI_SERVER=$CI_SERVER
   222    $CI_SERVER_NAME="AlloyCI CI"
   223    $env:CI_SERVER_NAME=$CI_SERVER_NAME
   224    $CI_SERVER_VERSION=""
   225    $env:CI_SERVER_VERSION=$CI_SERVER_VERSION
   226    $CI_SERVER_REVISION=""
   227    $env:CI_SERVER_REVISION=$CI_SERVER_REVISION
   228    $GITLAB_CI="true"
   229    $env:GITLAB_CI=$GITLAB_CI
   230    $GIT_SSL_CAINFO=""
   231    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   232    $GIT_SSL_CAINFO | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   233    $GIT_SSL_CAINFO="C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   234    $env:GIT_SSL_CAINFO=$GIT_SSL_CAINFO
   235    $CI_SERVER_TLS_CA_FILE=""
   236    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   237    $CI_SERVER_TLS_CA_FILE | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   238    $CI_SERVER_TLS_CA_FILE="C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   239    $env:CI_SERVER_TLS_CA_FILE=$CI_SERVER_TLS_CA_FILE
   240    echo "Cloning repository..."
   241    if( (Get-Command -Name Remove-Item2 -Module NTFSSecurity -ErrorAction SilentlyContinue) -and (Test-Path "C:\AlloyCI-Runner\builds\0\project-1" -PathType Container) ) {
   242      Remove-Item2 -Force -Recurse "C:\AlloyCI-Runner\builds\0\project-1"
   243    } elseif(Test-Path "C:\AlloyCI-Runner\builds\0\project-1") {
   244      Remove-Item -Force -Recurse "C:\AlloyCI-Runner\builds\0\project-1"
   245    }
   246  
   247    & "git" "clone" "https://alloy.com/group/project.git" "Z:/Gitlab/tests/test/builds/0/project-1"
   248    if(!$?) { Exit $LASTEXITCODE }
   249  
   250    cd "C:\AlloyCI-Runner\builds\0\project-1"
   251    if(!$?) { Exit $LASTEXITCODE }
   252  
   253    echo "Checking out db45ad9a as master..."
   254    & "git" "checkout" "db45ad9af9d7af5e61b829442fd893d96e31250c"
   255    if(!$?) { Exit $LASTEXITCODE }
   256  
   257    if(Test-Path "..\..\..\cache\project-1\pages\master\cache.tgz" -PathType Leaf) {
   258      echo "Restoring cache..."
   259      & "alloy-runner-windows-amd64.exe" "extract" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz"
   260      if(!$?) { Exit $LASTEXITCODE }
   261  
   262    } else {
   263      if(Test-Path "..\..\..\cache\project-1\pages\master\cache.tgz" -PathType Leaf) {
   264        echo "Restoring cache..."
   265        & "alloy-runner-windows-amd64.exe" "extract" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz"
   266        if(!$?) { Exit $LASTEXITCODE }
   267  
   268      }
   269    }
   270  }
   271  if(!$?) { Exit $LASTEXITCODE }
   272  
   273  & {
   274    $CI="true"
   275    $env:CI=$CI
   276    $CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
   277    $env:CI_COMMIT_REF=$CI_COMMIT_REF
   278    $CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
   279    $env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
   280    $CI_COMMIT_REF_NAME="master"
   281    $env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
   282    $CI_JOB_ID="1"
   283    $env:CI_JOB_ID=$CI_JOB_ID
   284    $CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
   285    $env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
   286    $CI_PROJECT_ID="1"
   287    $env:CI_PROJECT_ID=$CI_PROJECT_ID
   288    $CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
   289    $env:CI_PROJECT_DIR=$CI_PROJECT_DIR
   290    $CI_SERVER="yes"
   291    $env:CI_SERVER=$CI_SERVER
   292    $CI_SERVER_NAME="AlloyCI"
   293    $env:CI_SERVER_NAME=$CI_SERVER_NAME
   294    $CI_SERVER_VERSION=""
   295    $env:CI_SERVER_VERSION=$CI_SERVER_VERSION
   296    $CI_SERVER_REVISION=""
   297    $env:CI_SERVER_REVISION=$CI_SERVER_REVISION
   298    $GITLAB_CI="true"
   299    $env:GITLAB_CI=$GITLAB_CI
   300    $GIT_SSL_CAINFO=""
   301    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   302    $GIT_SSL_CAINFO | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   303    $GIT_SSL_CAINFO="C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   304    $env:GIT_SSL_CAINFO=$GIT_SSL_CAINFO
   305    $CI_SERVER_TLS_CA_FILE=""
   306    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   307    $CI_SERVER_TLS_CA_FILE | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   308    $CI_SERVER_TLS_CA_FILE="C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   309    $env:CI_SERVER_TLS_CA_FILE=$CI_SERVER_TLS_CA_FILE
   310    cd "C:\AlloyCI-Runner\builds\0\project-1"
   311    if(!$?) { Exit $LASTEXITCODE }
   312  
   313    echo "`$ echo true"
   314    echo true
   315  }
   316  if(!$?) { Exit $LASTEXITCODE }
   317  
   318  & {
   319    $CI="true"
   320    $env:CI=$CI
   321    $CI_COMMIT_REF="db45ad9af9d7af5e61b829442fd893d96e31250c"
   322    $env:CI_COMMIT_REF=$CI_COMMIT_REF
   323    $CI_COMMIT_BEFORE_SHA="d63117656af6ff57d99e50cc270f854691f335ad"
   324    $env:CI_COMMIT_BEFORE_SHA=$CI_COMMIT_BEFORE_SHA
   325    $CI_COMMIT_REF_NAME="master"
   326    $env:CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME
   327    $CI_JOB_ID="1"
   328    $env:CI_JOB_ID=$CI_JOB_ID
   329    $CI_REPOSITORY_URL="Z:\Gitlab\tests\test"
   330    $env:CI_REPOSITORY_URL=$CI_REPOSITORY_URL
   331    $CI_PROJECT_ID="1"
   332    $env:CI_PROJECT_ID=$CI_PROJECT_ID
   333    $CI_PROJECT_DIR="Z:/Gitlab/tests/test/builds/0/project-1"
   334    $env:CI_PROJECT_DIR=$CI_PROJECT_DIR
   335    $CI_SERVER="yes"
   336    $env:CI_SERVER=$CI_SERVER
   337    $CI_SERVER_NAME="AlloyCI"
   338    $env:CI_SERVER_NAME=$CI_SERVER_NAME
   339    $CI_SERVER_VERSION=""
   340    $env:CI_SERVER_VERSION=$CI_SERVER_VERSION
   341    $CI_SERVER_REVISION=""
   342    $env:CI_SERVER_REVISION=$CI_SERVER_REVISION
   343    $GITLAB_CI="true"
   344    $env:GITLAB_CI=$GITLAB_CI
   345    $GIT_SSL_CAINFO=""
   346    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   347    $GIT_SSL_CAINFO | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   348    $GIT_SSL_CAINFO="C:\AlloyCI-Runner\builds\0\project-1.tmp\GIT_SSL_CAINFO"
   349    $env:GIT_SSL_CAINFO=$GIT_SSL_CAINFO
   350    $CI_SERVER_TLS_CA_FILE=""
   351    md "C:\AlloyCI-Runner\builds\0\project-1.tmp" -Force | out-null
   352    $CI_SERVER_TLS_CA_FILE | Out-File "C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   353    $CI_SERVER_TLS_CA_FILE="C:\AlloyCI-Runner\builds\0\project-1.tmp\CI_SERVER_TLS_CA_FILE"
   354    $env:CI_SERVER_TLS_CA_FILE=$CI_SERVER_TLS_CA_FILE
   355    cd "C:\AlloyCI-Runner\builds\0\project-1"
   356    if(!$?) { Exit $LASTEXITCODE }
   357  
   358    echo "Archiving cache..."
   359    & "alloy-runner-windows-amd64.exe" "archive" "--file" "..\..\..\cache\project-1\pages\master\cache.tgz" "--path" "vendor"
   360    if(!$?) { Exit $LASTEXITCODE }
   361  
   362  }
   363  if(!$?) { Exit $LASTEXITCODE }
   364  ```
   365  
   366  [script]: https://github.com/AlloyCI/alloy_ci/tree/master/doc/json/README.md#script