Logstash ruby plugin to get the value from file and append

Hi,
I was trying to get the first line from the file and try to append the line into my logs,I am able to get the value from file but not able to append the value ..
I am doing like

if[classname] == "java.io.NotSerializableException"
{
ruby
{
code => "
f=File.open('D:/json/samplefile2.txt', &:readline)
puts(f) #here I am getting value 1236545
"
add_field => [ "id", "%{f}" ] # but here %{f}
}
}
}

Any idea how to resolve it ?

ruby {
  code => "
    event['id'] = File.open('D:/json/samplefile2.txt', &:readline)
  "
}

(Add .to_i if you want the id field to be an integer field.)

Thank you @magnusbaeck
Its working now