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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting environment with credentials method is broken? #31

Closed
Bargamut opened this issue Aug 10, 2020 · 2 comments
Closed

Converting environment with credentials method is broken? #31

Bargamut opened this issue Aug 10, 2020 · 2 comments

Comments

@Bargamut
Copy link

Describe the bug
The environment section parser bug: a special helper method credentials parser is broken. It's adding single quotes around method. Then it will be errors in pipeline.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'Pipeline As YAML Converter'
  2. Paste the code from Additional context
  3. Press 'Convert to Pipeline'
  4. See like environment section converted
    4.1 Press 'Valid' & see validation errors

Expected behavior
As expected by docs of environment syntax.
Convert this

environment:
  COVERALLS_SECRET_TOKEN: credentials('COVERALLS_SECRET_TOKEN')

to this (without quotes around credentials method):

environment {
  COVERALLS_SECRET_TOKEN = credentials('COVERALLS_SECRET_TOKEN')
}

Desktop (please complete the following information):

  • Ubuntu 18.04 on server, Linux Mint 20 on desktop
  • Chrome 84 on desktop

Additional context
I have code like this:

pipeline
  agent:
    label: 'master'
  stages:
    - stage: Tests
      stages:
        - stage: Start tests
          environment:
            COVERALLS_SECRET_TOKEN: credentials('COVERALLS_SECRET_TOKEN')
          steps:
            - echo "====++++executing Start tests++++===="
            - echo "COVERALLS_SECRET_TOKEN = ${COVERALLS_SECRET_TOKEN}"
            - sh 'npm install'
            - sh 'npm test'
          post:
            always:
              - echo "====++++always++++===="
            success:
              - echo "====++++Start tests executed successfully++++===="
              - sh 'npm run coverage'
            failure:
              - echo "====++++Start tests execution failed++++===="

and this is parsing result:

pipeline {
  agent {
    node {
      label 'master'
    }
  }
  stages {
    stage('Tests') {
      stages {
        stage('Start tests') {
          environment {
            COVERALLS_SECRET_TOKEN = 'credentials('COVERALLS_SECRET_TOKEN')'
          }
          steps {
            echo "====++++executing Start tests++++===="
            echo "COVERALLS_SECRET_TOKEN = ${COVERALLS_SECRET_TOKEN}"
            sh 'npm install'
            sh 'npm test'
          }

Validation says that:

startup failed:
WorkflowScript: 18: Environment variable values must either be single quoted, double quoted, or function calls. @ line 18, column 50.
LS_SECRET_TOKEN = 'credentials('COVERALLS_
^

WorkflowScript: 17: No variables specified for environment @ line 17, column 11.
environment {
^

2 errors
@aytuncbeken
Copy link
Contributor

aytuncbeken commented Dec 20, 2020

Hi @Bargamut,

Thanks for the detailed explanation. I've made the changes regarding the usage of the credentials in Environments.

Parser will parse this definitions

pipeline:
  agent:
    label: 'master'
  stages:
    - stage: Tests
      stages:
        - stage: Start tests
          environment:
            KEY1: 'VAL1'
            KEY2: "VAL2"
            COVERALLS_SECRET_TOKEN: credentials('COVERALLS_SECRET_TOKEN')

to this

pipeline {
  agent {
    node {
      label 'master'
    }
  }
  stages {
    stage('Tests') {
      stages {
        stage('Start tests') {
          environment {
            KEY1 = 'VAL1'
            KEY2 = 'VAL2'
            COVERALLS_SECRET_TOKEN = credentials('COVERALLS_SECRET_TOKEN')
          }
        }
      }
    }
  }
}

in the next release.

@aytuncbeken
Copy link
Contributor

Released with 0.14-rc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants