title: How to convert freestyle jenkins to jenkins scripted pipeline
body: <p>I am writing because for several weeks I have been struggling with rewriting the freestyle jenkins code that was executed in the / bin / bash shell on the pipeline.
  At the beginning, I was wondering what type of pipeline to choose, whether it is a declarative pipeline or a scripted pipeline. I chose the scripted pipeline because with this script I run gulp that the pipeline declarative would not have access to.</p>
  <p>The first problem I encountered was the lack of a file in the $ {WORKSPACE}/artifacts directory for a given job, which I previously uploaded using the add file option:</p>
  <p><a href="https://i.stack.imgur.com/QS0Ps.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QS0Ps.png" alt="File" /></a></p>
  <p>this was not a problem in the freestyle pipeline.</p>
  <p>Second problem, how should I write variables in the scripted pipeline
  is something like below correct ??</p>
  <pre><code>def artifacts_dir=&quot;\${WORKSPACE}/artifacts&quot;
  def artefact_dir= &quot;\${WORKSPACE}/artifacts}&quot;
  def scfs_dir=&quot;\${WORKSPACE}/scf_migration_validator/scf_data/baseline/SBTS/&quot;
  def admin_trunk_dir=&quot;/home/jenkins/admin_repos/admin_trunk&quot;
  def cores=14
  
  
  build_admin_html (dir, branch) {
    sh &quot;&quot;&quot;
    #!/bin/bash
    set +x 
    touch rules.pdl
    echo Building admin HTML!
    cd ${dir}/admin
    cp ${artifacts_dir}/rules.pdl ${dir}/admin/admin-core/resources/pdlValidation/PDL/SRAN/
    gulp package --skip-wasm --svn-branch=${branch} --max-old-space-size=8192 --use-local --no-auth
    cp ${dir}/admin/.tmp/bundles/no-auth/ADMIN.html ${artifacts_dir}
    echo
    &quot;&quot;&quot;
  }
  
  
  timestamps {
  
  node ('local-docker') { 
  
      stage ('Build_Knife - Checkout') {
       checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'cab881bd-a4c4-41d8-aa9c-74a20d341903', url: 'git@wrgitlab.ext.net.nokia.com:szmajdzi/pdl-testing.git']]]) 
      }
      stage ('Build_Knife - Build') {
      
      build_admin_html (admin_trunk_dir, 'trunk')
      
      }
     }
    }
  </code></pre>
  <p>I should write like this:</p>
  <pre><code>$ {artifacts_dir}
  or so
  \ $ {artifacts_dir}
  </code></pre>