如何在gocd步骤中传递环境变量作为参数。在这里,当我传递$ {KAFKA_CODE}时,它给出了错误。当我仅传递$ KAFKA_CODE时,命令在群集上以aws s3 cp $KAFKA_CODE /home/hadoop/
的形式提交。但是我希望它像aws s3 cp s3://code_path/spark-jobs.zip /home/hadoop/
一样,请让我知道如何解决,因为我刚接触gocd
format_version: 3
pipelines:
copy_code_cluster:
group: MyGroup
materials:
terraform_git:
git: git@gitlab.xxxx.com/spark-jobs.git
branch: develop
environment_variables:
KAFKA_CODE: "s3://code_path/spark-jobs.zip"
stages:
- provision:
clean_workpace: true
jobs:
terraform:
tasks:
- exec:
command: /bin/sh
arguments:
- "-c"
- "aws emr add-steps --cluster-id 'j-xxxxxxx' --steps 'Name= \"copy zip to cluster home directory\" , Jar=\"command-runner.jar\",Args=[ \"aws\" , \"s3\" , \"cp\", \"$KAFKA_CODE\" , \"/home/hadoop/\"]' "
答案 0 :(得分:0)
这通过使用参数而不是environment_variables解决。无法在任务内部访问environment_variables。只能访问参数。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
MAIN CLASS
public class EmployeeInformation {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//
Scanner sc = new Scanner (System.in);
System.out.println("");
String Name = sc.next();
Employee myemp = new Employee(Name);
myemp.getName();
myemp.addEmployee();
String name = sc.next();
}
}
PARENT CLASS
package employeeinformation;
public class Person {
private String name;
private String ID;
private String address;
private String gender;
public Person(String Name , String ID, String address, String gender)
{
this.name = Name;
this.ID = ID;
this.address = address;
this.gender = gender;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the ID
*/
public String getID() {
return ID;
}
/**
* @param ID the ID to set
*/
public void setID(String ID) {
this.ID = ID;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* @return the gender
*/
public String getGender() {
return gender;
}
/**
* @param gender the gender to set
*/
public void setGender(String gender) {
this.gender = gender;
}
}
CHILD CLASS
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package employeeinformation;
import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author salomon
*/
public class Employee extends Person {
Scanner sc = new Scanner (System.in);
private String employmentType;
private String empID;
ArrayList<Employee> el = new ArrayList<Employee>();
Employee(String Name, String ID, String address, String gender, String employmentType, String empID) {
super(Name, ID, address, gender);
setEmpID(empID);
setEmploymentType(employmentType);
}
/**
* @return the employmentType
*/
public String getEmploymentType() {
return employmentType;
}
/**
* @param employmentType the employmentType to set
*/
public void setEmploymentType(String employmentType) {
this.employmentType = employmentType;
}
/**
* @return the accesscard
*/
public void addEmployee()å
{
System.out.println("Enter your Full Name");
String name = sc.next();
System.out.println("Enter your NRIC/ID");
String ID = sc.next();
System.out.println("Enter your Address");
String address = sc.next();
System.out.println("Enter your Gender");
String gender = sc.next();
System.out.println("Enter your Employment Type");
String employmentType = sc.next();
System.out.println("Enter your Employment ID");
String employmentID = sc.next();
Employee empobj;
empobj = new Employee(name, ID, address, gender, employmentType, getEmpID());
el.add(empobj);
System.out.println(el);
}
@Override
public String toString() {
return "Employee Details " + getName() + getAddress() + getID() + getGender(); //To change body of generated methods, choose Tools | Templates.
}
/**
* @return the empID
*/
public String getEmpID() {
return empID;
}
/**
* @param empID the empID to set
*/
public void setEmpID(String empID) {
this.empID = empID;
}
/**
* @param empID the empID to set
*/
}